haskell - 模块 ‘main’ 未导出 IO 操作 ‘Main’

标签 haskell

我有两个名为 SimpleJSON.hs 的 haskell 文件,另一个是 Main.hs

--File: SimpleJSON.hs
module SimpleJSON
(
    JValue (..)
    ,getString
    ,getInt
    ,getDouble
    ,getBool
    ,getObject
    ,getArray
    ,isNull
) where

data JValue = JString String
        | JNumber Double
        | JBool Bool
        | JNull
        | JObject [(String, JValue)]
        | JArray [JValue]
          deriving (Eq, Ord, Show)


--File: Main.hs
module Main () where
import SimpleJSON
main = print (JObject [("foo", JNumber 1), ("bar", JBool False)])

所以在编译的时候
我在做
ghc -c SimpleJSON.hs


ghc simple Main.hs SimpleJSON.o

然后我收到错误
Main.hs:1:1: error:
The IO action ‘main’ is not exported by module ‘Main’
  |
1 | module Main () where
  | ^

如何解决这个编译错误?

最佳答案

应该

module Main where

或者
module Main (main) where

关于haskell - 模块 ‘main’ 未导出 IO 操作 ‘Main’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53685213/

相关文章:

haskell - Haskell中的句柄是半封闭错误?

haskell - 类型类定义中类型的解构(Haskell)

haskell - -XAllowAmbigouslyTypes 什么时候合适?

Haskell FFI - mallocForeignPtr 用法

ruby - 为什么 Haskell 没有符号(像 ruby​​)/原子(像 erlang)?

haskell - Haddock - 链接到外部模块中的功能(导入整个模块)

haskell - 类型构造函数可以与值构造函数相同吗?

haskell - 不能在 IO 上下文中使用 state monad

scala - 如何通用地组合返回不同 monads 的 monadic 函数?

haskell - Haskell do block 中如何允许表达式