@@ -9,7 +9,6 @@ import qualified Data.Char as Char
9import qualified Data.Map as Map
9import qualified Data.Map as Map
10import Data.Monoid ((<>))
10import Data.Monoid ((<>))
11import qualified Data.Text as Text
11import qualified Data.Text as Text
12−import qualified Data.UnionFind.IO as UF
13import Data.Text (Text)
12import Data.Text (Text)
15import qualified AST.Type as T
14import qualified AST.Type as T
@@ -17,49 +16,32 @@ import qualified AST.Variable as Var
17import qualified Reporting.Annotation as A
16import qualified Reporting.Annotation as A
18import qualified Reporting.Error.Type as Error
17import qualified Reporting.Error.Type as Error
19import qualified Reporting.Region as R
18import qualified Reporting.Region as R
19+import qualified Type.UnionFind as UF
23−-- CONCRETE TYPES
23+-- TYPE PRIMITIVES
30type Variable =
26type Variable =
31 UF.Point Descriptor
27 UF.Point Descriptor
34−type TypeConstraint =
30+data FlatType
35− Constraint Type Variable
31+ = App1 Variable Variable
36−
32+ | Fun1 Variable Variable
49 | EmptyRecord1
33 | EmptyRecord1
50− | Record1 (Map.Map Text a) a
34+ | Record1 (Map.Map Text Variable) Variable
53−data TermN a
37+data Type
54 = PlaceHolder Text
38 = PlaceHolder Text
55− | AliasN Var.Canonical [(Text, TermN a)] (TermN a)
39+ | AliasN Var.Canonical [(Text, Type)] Type
56− | VarN a
40+ | VarN Variable
57− | TermN (Term1 (TermN a))
41+ | AppN Type Type
60−record :: Map.Map Text (TermN a) -> TermN a -> TermN a
44+ | RecordN (Map.Map Text Type) Type
62− TermN (Record1 fs rec)
@@ -76,7 +58,7 @@ data Descriptor =
78data Content
60data Content
79− = Structure (Term1 Variable)
61+ = Structure FlatType
80 | Atom Var.Canonical
62 | Atom Var.Canonical
81 | Var Flex (Maybe Super) (Maybe Text)
63 | Var Flex (Maybe Super) (Maybe Text)
82 | Alias Var.Canonical [(Text,Variable)] Variable
64 | Alias Var.Canonical [(Text,Variable)] Variable
@@ -126,23 +108,24 @@ getVarNamesMark =
126-- CONSTRAINTS
108-- CONSTRAINTS
129−data Constraint a b
111+data Constraint
131 | CSaveEnv
113 | CSaveEnv
132− | CEqual Error.Hint R.Region a a
114+ | CEqual Error.Hint R.Region Type Type
133− | CAnd [Constraint a b]
115+ | CAnd [Constraint]
134− | CLet [Scheme a b] (Constraint a b)
116+ | CLet [Scheme] Constraint
135− | CInstance R.Region SchemeName a
117+ | CInstance R.Region SchemeName Type
138type SchemeName = Text
120type SchemeName = Text
141−data Scheme a b = Scheme
123+data Scheme =
142− { _rigidQuantifiers :: [b]
125+ { _rigidQuantifiers :: [Variable]
143− , _flexibleQuantifiers :: [b]
126+ , _flexibleQuantifiers :: [Variable]
144− , _constraint :: Constraint a b
127+ , _constraint :: Constraint
145− , _header :: Map.Map Text (A.Located a)
128+ , _header :: Map.Map Text (A.Located Type)
@@ -153,14 +136,16 @@ data Scheme a b = Scheme
153infixr 9 ==>
136infixr 9 ==>
156(==>) :: Type -> Type -> Type
140(==>) :: Type -> Type -> Type
157−(==>) a b =
141+(==>) =
158− TermN (Fun1 a b)
142+ FunN
161−(<|) :: TermN a -> TermN a -> TermN a
145+{-# INLINE (<|) #-}
146+(<|) :: Type -> Type -> Type
163− TermN (App1 f a)
148+ AppN
@@ -211,7 +196,7 @@ toSuper name =
211-- CONSTRAINT HELPERS
196-- CONSTRAINT HELPERS
214−monoscheme :: Map.Map Text (A.Located a) -> Scheme a b
199+monoscheme :: Map.Map Text (A.Located Type) -> Scheme
215monoscheme headers =
200monoscheme headers =
216 Scheme [] [] CTrue headers
201 Scheme [] [] CTrue headers
@@ -219,7 +204,7 @@ monoscheme headers =
219infixl 8 /\
204infixl 8 /\
222−(/\) :: Constraint a b -> Constraint a b -> Constraint a b
207+(/\) :: Constraint -> Constraint -> Constraint
223(/\) c1 c2 =
208(/\) c1 c2 =
224 case (c1, c2) of
209 case (c1, c2) of
225 (CTrue, _) -> c2
210 (CTrue, _) -> c2
@@ -228,23 +213,23 @@ infixl 8 /\
230-- ex qs constraint == exists qs. constraint
215-- ex qs constraint == exists qs. constraint
231−ex :: [Variable] -> TypeConstraint -> TypeConstraint
216+ex :: [Variable] -> Constraint -> Constraint
232ex fqs constraint =
217ex fqs constraint =
233 CLet [Scheme [] fqs constraint Map.empty] CTrue
218 CLet [Scheme [] fqs constraint Map.empty] CTrue
236−forall :: [Variable] -> TypeConstraint -> TypeConstraint
221+forall :: [Variable] -> Constraint -> Constraint
237forall rqs constraint =
222forall rqs constraint =
238 CLet [Scheme rqs [] constraint Map.empty] CTrue
223 CLet [Scheme rqs [] constraint Map.empty] CTrue
241−exists :: (Type -> IO TypeConstraint) -> IO TypeConstraint
226+exists :: (Type -> IO Constraint) -> IO Constraint
242exists f =
227exists f =
243 do v <- mkVar Nothing
228 do v <- mkVar Nothing
244 ex [v] <$> f (VarN v)
229 ex [v] <$> f (VarN v)
247−existsNumber :: (Type -> IO TypeConstraint) -> IO TypeConstraint
232+existsNumber :: (Type -> IO Constraint) -> IO Constraint
248existsNumber f =
233existsNumber f =
249 do v <- mkVar (Just Number)
234 do v <- mkVar (Just Number)
250 ex [v] <$> f (VarN v)
235 ex [v] <$> f (VarN v)
@@ -304,7 +289,7 @@ contentToSrcType variable content =
304 return (T.Var "?")
289 return (T.Var "?")
307−termToSrcType :: Term1 Variable -> StateT NameState IO T.Canonical
292+termToSrcType :: FlatType -> StateT NameState IO T.Canonical
308termToSrcType term =
293termToSrcType term =
309 case term of
294 case term of
310 App1 func arg ->
295 App1 func arg ->
@@ -344,7 +329,8 @@ termToSrcType term =
344-- MANAGE FRESH VARIABLE NAMES
329-- MANAGE FRESH VARIABLE NAMES
347−data NameState = NameState
332+data NameState =
348 { _taken :: TakenNames
334 { _taken :: TakenNames
349 , _normals :: Int
335 , _normals :: Int
350 , _numbers :: Int
336 , _numbers :: Int