「Real World Haskell」読書メモ 4.ライブラリを書く 5.5Haskellプログラムの生成、およびモジュールのインポート
-- file: ch05/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 :: JValue -> Maybe Int getInt (JNumber n) = Just (truncate n) getInt _ = Nothing getDouble :: JValue -> Maybe Double getDouble (JNumber n) = Just n getDouble _ = Nothing getBool :: JValue -> Maybe Bool getBool (JBool b) = Just b getBool _ = Nothing getObject :: JValue -> Maybe [(String, JValue)] getObject (JObject o) = Just o getObject _ = Nothing getArray :: JValue -> Maybe [JValue] getArray (JArray a) = Just a getArray _ = Nothing isNull :: JValue -> Bool isNull v = v == JNull
-- file: ch05/Main.hs module Main () where import SimpleJSON main = print (JObject [("foo", JNumber 1), ("bar", JBool False)])
PS D:\haskell\json> ghc --make Main.hs -o json [1 of 2] Compiling SimpleJSON ( SimpleJSON.hs, SimpleJSON.o ) [2 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:1:0: The main function `main' is not exported by module `Main'
"module Main where" に修正して全てをエクスポートするか、 "module Main (main) where" として main を指定してエクスポートすれば OK。