@@ -2,9 +2,8 @@
22{-# LANGUAGE OverloadedStrings #-}
33module Type.Constraint
44 ( Constraint(..)
5− , (/\), ex, forall
6− , exists, existsNumber
7− , Scheme(..), SchemeName
5+ , ex
6+ , Scheme(..)
87 , monoscheme
98 )
109 where
@@ -12,11 +11,12 @@ module Type.Constraint
1211
1312import qualified Data.Map.Strict as Map
1413
14+import qualified AST.Canonical as Can
1515import qualified Elm.Name as N
1616import qualified Reporting.Annotation as A
1717import qualified Reporting.Error.Type as Error
1818import qualified Reporting.Region as R
19−import Type.Type (Type(VarN), Variable, mkFlexVar, mkFlexNumber)
19+import Type.Type (Type, Variable)
2020
2121
2222
@@ -25,26 +25,25 @@ import Type.Type (Type(VarN), Variable, mkFlexVar, mkFlexNumber)
2525
2626data Constraint
2727 = CTrue
28− | CSaveEnv
29− | CEqual Error.Hint R.Region Type Type
28+ | CSaveHeaders
29+ | CEqual R.Region Error.Context Error.Category R.Region Type Type
30+ | CLookup R.Region Error.Context R.Region N.Name Type
31+ | CInstance R.Region Error.Context R.Region Can.Type Type
32+ | CPattern R.Region Error.PatternContext Error.PatternCategory R.Region Type Type
3033 | CAnd [Constraint]
3134 | CLet [Scheme] Constraint
32− | CInstance R.Region SchemeName Type
3335
3436
3537
3638-- SCHEMES
3739
3840
39−type SchemeName = N.Name
40−
41−
4241data Scheme =
4342 Scheme
44− { _rigidQuantifiers :: [Variable]
45− , _flexibleQuantifiers :: [Variable]
46− , _constraint :: Constraint
43+ { _rigidVars :: [Variable]
44+ , _flexVars :: [Variable]
4745 , _header :: Map.Map N.Name (A.Located Type)
46+ , _constraint :: Constraint
4847 }
4948
5049
@@ -54,42 +53,17 @@ data Scheme =
5453
5554monoscheme :: Map.Map N.Name (A.Located Type) -> Scheme
5655monoscheme headers =
57− Scheme [] [] CTrue headers
56+ Scheme [] [] headers CTrue
5857
5958
6059
6160-- CONSTRAINT HELPERS
6261
6362
64−infixl 8 /\
65−
66−
67−(/\) :: Constraint -> Constraint -> Constraint
68−(/\) c1 c2 =
69− case (c1, c2) of
70− (CTrue, _) -> c2
71− (_, CTrue) -> c1
72− _ -> CAnd [c1,c2]
73−
74−
7563-- ex qs constraint == exists qs. constraint
7664ex :: [Variable] -> Constraint -> Constraint
77−ex fqs constraint =
78− CLet [Scheme [] fqs constraint Map.empty] CTrue
79−
80−
81−forall :: [Variable] -> Constraint -> Constraint
82−forall rqs constraint =
83− CLet [Scheme rqs [] constraint Map.empty] CTrue
84−
85−
86−exists :: (Type -> IO Constraint) -> IO Constraint
87−exists f =
88− do v <- mkFlexVar
89− ex [v] <$> f (VarN v)
90−
91−
92−existsNumber :: (Type -> IO Constraint) -> IO Constraint
93−existsNumber f =
94− do v <- mkFlexNumber
95− ex [v] <$> f (VarN v)
65+ex flexVars constraint =
66+ CLet
67+ [ Scheme [] flexVars Map.empty constraint
68+ ]
69+ CTrue