haskell - 为什么这个 [haskell] 编译错误?

标签 haskell compiler-errors

module Main

alicebob :: String -> String
alicebob "alice" = "Hi alice"
alicebob "bob" = "Hi bob"
alicebob _ = "Hi person whose name is neither alice nor bob."

greet :: IO ()
greet = do
      putStrLn "hi. whats your name?"
      name <- getLine
      putStrLn (alicebob name)

简单的编程练习,以获得一些用户输入和回复。刚开始学习haskell,所以请原谅这个简单的问题。在线 alicebob :: String -> String 出现错误.
我该如何解决?

最佳答案

模块头必须包含 where ,

module Main where
--          ^^^^^

编译器期望找到 where (可能前面有一个导出列表)以及当它找到 alicebob 时相反,它会引发错误。

关于haskell - 为什么这个 [haskell] 编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19058941/

相关文章:

haskell - 函数和克莱斯利箭头的应用

haskell - 这个上下文是什么意思 : (Monad m, (~) * a ())?

java - 在Java中将十进制转换为二进制

c++ - 使用CMake链接Boost(Ubuntu 14.04)

xamarin - Windows运行时元数据在SDK中无效-ITIL00005

java - Set <Figura2D>类型的方法add(Figura2D)不适用于参数(Rettangolo)

haskell - 多包项目中的测试输出未显示为 `stack test`

haskell - 在 do block 内迭代

haskell - 在 Haskell 中导航和修改基于 Free monad 的 AST

c - C编译器在功能之前需要标识符