@@ -10,6 +10,7 @@ import qualified Data.ByteString.Lazy.Char8 as BS
1010import qualified Data.Text as Text
1111
1212import qualified Elm.Compiler.Module as Module
13+import qualified Elm.Compiler.Type as Type
1314
1415
1516data Documentation = Documentation
@@ -25,7 +26,7 @@ data Alias = Alias
2526 { aliasName :: String
2627 , aliasComment :: String
2728 , aliasArgs :: [String]
28− , aliasType :: Type
29+ , aliasType :: Type.Type
2930 }
3031
3132
@@ -33,26 +34,18 @@ data Union = Union
3334 { unionName :: String
3435 , unionComment :: String
3536 , unionArgs :: [String]
36− , unionCases :: [(String, [Type])]
37+ , unionCases :: [(String, [Type.Type])]
3738 }
3839
3940
4041data Value = Value
4142 { valueName :: String
4243 , valueComment :: String
43− , valueType :: Type
44+ , valueType :: Type.Type
4445 , valueAssocPrec :: Maybe (String,Int)
4546 }
4647
4748
48−data Type
49− = Lambda Type Type
50− | Var String
51− | Type String
52− | App Type [Type]
53− | Record [(String, Type)] (Maybe Type)
54−
55−
5649-- JSON for DOCUMENTATION
5750
5851instance Json.ToJSON Documentation where
@@ -156,65 +149,3 @@ instance Json.FromJSON Value where
156149 parseJSON value =
157150 fail $ "Cannot decode Value from: " ++ BS.unpack (Json.encode value)
158151
159−
160−-- JSON for TYPE
161−
162−instance Json.ToJSON Type where
163− toJSON tipe =
164− Json.object (getFields tipe)
165− where
166− getFields tipe =
167− case tipe of
168− Lambda t1 t2 ->
169− [ "tag" .= ("lambda" :: Text.Text)
170− , "in" .= Json.toJSON t1
171− , "out" .= Json.toJSON t2
172− ]
173−
174− Var x ->
175− [ "tag" .= ("var" :: Text.Text)
176− , "name" .= Json.toJSON x
177− ]
178−
179− Type name ->
180− [ "tag" .= ("type" :: Text.Text)
181− , "name" .= Json.toJSON name
182− ]
183−
184− App t ts ->
185− [ "tag" .= ("app" :: Text.Text)
186− , "func" .= Json.toJSON t
187− , "args" .= Json.toJSON ts
188− ]
189−
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
194− ]
195−
196−instance Json.FromJSON Type where
197− parseJSON (Json.Object obj) =
198− do tag <- obj .: "tag"
199− case (tag :: String) of
200− "lambda" ->
201− Lambda <$> obj .: "in" <*> obj .: "out"
202−
203− "var" ->
204− Var <$> obj .: "name"
205−
206− "type" ->
207− Type <$> obj .: "name"
208−
209− "app" ->
210− App <$> obj .: "func" <*> obj .: "args"
211−
212− "record" ->
213− Record <$> obj .: "fields" <*> obj .: "extension"
214−
215− _ ->
216− fail $ "Error when decoding type with tag: " ++ tag
217−
218−
219− parseJSON value =
220− fail $ "Cannot decode Value from: " ++ BS.unpack (Json.encode value)