@@ -10,6 +10,7 @@ import qualified Data.ByteString.Lazy.Char8 as BS
10import qualified Data.Text as Text
10import qualified Data.Text as Text
12import qualified Elm.Compiler.Module as Module
12import qualified Elm.Compiler.Module as Module
13+import qualified Elm.Compiler.Type as Type
15data Documentation = Documentation
16data Documentation = Documentation
@@ -25,7 +26,7 @@ data Alias = Alias
25 { aliasName :: String
26 { aliasName :: String
26 , aliasComment :: String
27 , aliasComment :: String
27 , aliasArgs :: [String]
28 , aliasArgs :: [String]
28− , aliasType :: Type
29+ , aliasType :: Type.Type
@@ -33,26 +34,18 @@ data Union = Union
33 { unionName :: String
34 { unionName :: String
34 , unionComment :: String
35 , unionComment :: String
35 , unionArgs :: [String]
36 , unionArgs :: [String]
36− , unionCases :: [(String, [Type])]
37+ , unionCases :: [(String, [Type.Type])]
40data Value = Value
41data Value = Value
41 { valueName :: String
42 { valueName :: String
42 , valueComment :: String
43 , valueComment :: String
43− , valueType :: Type
44+ , valueType :: Type.Type
44 , valueAssocPrec :: Maybe (String,Int)
45 , valueAssocPrec :: Maybe (String,Int)
53− | Record [(String, Type)] (Maybe Type)
56-- JSON for DOCUMENTATION
49-- JSON for DOCUMENTATION
58instance Json.ToJSON Documentation where
51instance Json.ToJSON Documentation where
@@ -156,65 +149,3 @@ instance Json.FromJSON Value where
156 parseJSON value =
149 parseJSON value =
157 fail $ "Cannot decode Value from: " ++ BS.unpack (Json.encode value)
150 fail $ "Cannot decode Value from: " ++ BS.unpack (Json.encode value)
162−instance Json.ToJSON Type where
164− Json.object (getFields tipe)
169− [ "tag" .= ("lambda" :: Text.Text)
170− , "in" .= Json.toJSON t1
171− , "out" .= Json.toJSON t2
175− [ "tag" .= ("var" :: Text.Text)
176− , "name" .= Json.toJSON x
180− [ "tag" .= ("type" :: Text.Text)
181− , "name" .= Json.toJSON name
185− [ "tag" .= ("app" :: Text.Text)
186− , "func" .= Json.toJSON t
187− , "args" .= Json.toJSON ts
190− Record fields ext ->
191− [ "tag" .= ("record" :: Text.Text)
192− , "fields" .= Json.toJSON (map (Json.toJSON . second Json.toJSON) fields)
193− , "extension" .= Json.toJSON ext
196−instance Json.FromJSON Type where
197− parseJSON (Json.Object obj) =
198− do tag <- obj .: "tag"
199− case (tag :: String) of
201− Lambda <$> obj .: "in" <*> obj .: "out"
204− Var <$> obj .: "name"
207− Type <$> obj .: "name"
210− App <$> obj .: "func" <*> obj .: "args"
213− Record <$> obj .: "fields" <*> obj .: "extension"
216− fail $ "Error when decoding type with tag: " ++ tag
220− fail $ "Cannot decode Value from: " ++ BS.unpack (Json.encode value)