on master help sign in
Switch to representation of types discussed with @deadfoxygrandpa
f727bf9Evan Czaplicki
compiler/Docs.hs+12−12
@@ -16,8 +16,8 @@ import qualified Data.Map as Map
16import qualified Data.ByteString.Lazy as BS
16import qualified Data.ByteString.Lazy as BS
17import qualified Data.Text as Text
17import qualified Data.Text as Text
18
18
19−import SourceSyntax.Helpers (isSymbol)
19+import qualified SourceSyntax.Helpers as Help
20−import SourceSyntax.Type (Type(..))
20+import qualified SourceSyntax.Type as T
21import qualified SourceSyntax.Expression as E
21import qualified SourceSyntax.Expression as E
22import qualified SourceSyntax.Declaration as D
22import qualified SourceSyntax.Declaration as D
23
23
@@ -122,7 +122,7 @@ collect infixes types aliases adts things =
122 where
122 where
123 nonCustomOps = Map.mapWithKey addDefaultInfix $ Map.difference types infixes
123 nonCustomOps = Map.mapWithKey addDefaultInfix $ Map.difference types infixes
124 addDefaultInfix name pairs
124 addDefaultInfix name pairs
125− | all isSymbol name = addInfix (D.L, 9 :: Int) pairs
125+ | all Help.isSymbol name = addInfix (D.L, 9 :: Int) pairs
126 | otherwise = pairs
126 | otherwise = pairs
127
127
128 customOps = Map.intersectionWith addInfix infixes types
128 customOps = Map.intersectionWith addInfix infixes types
@@ -139,7 +139,7 @@ collect infixes types aliases adts things =
139 let fields = ["typeVariables" .= vars, "type" .= tipe ]
139 let fields = ["typeVariables" .= vars, "type" .= tipe ]
140 in collect infixes types (insert name fields aliases) adts rest
140 in collect infixes types (insert name fields aliases) adts rest
141 D.Datatype name vars ctors ->
141 D.Datatype name vars ctors ->
142− let tipe = Data name (map Var vars)
142+ let tipe = T.Data name (map T.Var vars)
143 fields = ["typeVariables" .= vars
143 fields = ["typeVariables" .= vars
144 , "constructors" .= map (ctorToJson tipe) ctors ]
144 , "constructors" .= map (ctorToJson tipe) ctors ]
145 in collect infixes types aliases (insert name fields adts) rest
145 in collect infixes types aliases (insert name fields adts) rest
@@ -148,28 +148,28 @@ collect infixes types aliases adts things =
148 obj name fields =
148 obj name fields =
149 [ "name" .= name, "raw" .= source, "comment" .= comment ] ++ fields
149 [ "name" .= name, "raw" .= source, "comment" .= comment ] ++ fields
150
150
151−instance ToJSON Type where
151+instance ToJSON T.Type where
152 toJSON tipe =
152 toJSON tipe =
153 object $
153 object $
154 case tipe of
154 case tipe of
155− Lambda t1 t2 ->
155+ T.Lambda t1 t2 ->
156 [ "tag" .= ("function" :: Text.Text)
156 [ "tag" .= ("function" :: Text.Text)
157− , "input" .= toJSON t1
157+ , "args" .= toJSON (T.collectLambdas t1)
158− , "output" .= toJSON t2
158+ , "result" .= toJSON t2
159 ]
159 ]
160
160
161− Var x ->
161+ T.Var x ->
162 [ "tag" .= ("var" :: Text.Text)
162 [ "tag" .= ("var" :: Text.Text)
163 , "name" .= toJSON x
163 , "name" .= toJSON x
164 ]
164 ]
165
165
166− Data name ts ->
166+ T.Data name ts ->
167 [ "tag" .= ("adt" :: Text.Text)
167 [ "tag" .= ("adt" :: Text.Text)
168 , "name" .= toJSON name
168 , "name" .= toJSON name
169 , "args" .= map toJSON ts
169 , "args" .= map toJSON ts
170 ]
170 ]
171
171
172− Record fields ext ->
172+ T.Record fields ext ->
173 [ "tag" .= ("record" :: Text.Text)
173 [ "tag" .= ("record" :: Text.Text)
174 , "fields" .= toJSON (map (toJSON . second toJSON) fields)
174 , "fields" .= toJSON (map (toJSON . second toJSON) fields)
175 , "extension" .= toJSON ext
175 , "extension" .= toJSON ext
@@ -177,4 +177,4 @@ instance ToJSON Type where
177
177
178ctorToJson tipe (ctor, tipes) =
178ctorToJson tipe (ctor, tipes) =
179 object [ "name" .= ctor
179 object [ "name" .= ctor
180− , "type" .= foldr Lambda tipe tipes ]
180+ , "type" .= foldr T.Lambda tipe tipes ]