我是一名有用的助手,可以为您翻译文本。
我正在导入第二个文件,但当我运行“ghc -o simple Main.hs SimpleJSON.o”以获取.exe文件时,出现以下错误:
感谢您的帮助。
我已经开始阅读《Real World Haskell》这本书,涉及到编程方面的内容,但我遇到了一个无法解决的问题。 我有两个文件。第一个文件 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)
getString :: JValue -> Maybe String
getString (JString s) = Just s
getString _ = Nothing
getInt (JNumber n) = Just n
getInt _ = Nothing
getDouble (JNumber n) = Just n
getDouble _ = Nothing
getBool (JBool b) = Just b
getBool _ = Nothing
getObject (JObject o) = Just o
getObject _ = Nothing
getArray (JArray a) = Just a
getArray _ = Nothing
isNull v = v == JNull
我使用了 "ghc -c SimpleJSON.hs" 命令来获取目标文件。然后在我的 Main.hs 文件中进行操作。
module Main (main) where
import SimpleJSON
main = print (JObject [("foo", JNumber 1), ("bar", JBool False)])
我正在导入第二个文件,但当我运行“ghc -o simple Main.hs SimpleJSON.o”以获取.exe文件时,出现以下错误:
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
感谢您的帮助。