on master help sign in
Cut a bunch of helper functions from Type.Constraint
3949a04Evan Czaplicki
src/Type/Constraint.hs+18−44
@@ -2,9 +2,8 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Type.Constraint
3module Type.Constraint
4 ( Constraint(..)
4 ( Constraint(..)
5− , (/\), ex, forall
5+ , ex
6− , exists, existsNumber
7− , Scheme(..), SchemeName
6+ , Scheme(..)
8 , monoscheme
7 , monoscheme
9 )
8 )
10 where
9 where
@@ -12,11 +11,12 @@ module Type.Constraint
12
11
13import qualified Data.Map.Strict as Map
12import qualified Data.Map.Strict as Map
14
13
14+import qualified AST.Canonical as Can
15import qualified Elm.Name as N
15import qualified Elm.Name as N
16import qualified Reporting.Annotation as A
16import qualified Reporting.Annotation as A
17import qualified Reporting.Error.Type as Error
17import qualified Reporting.Error.Type as Error
18import qualified Reporting.Region as R
18import qualified Reporting.Region as R
19−import Type.Type (Type(VarN), Variable, mkFlexVar, mkFlexNumber)
19+import Type.Type (Type, Variable)
20
20
21
21
22
22
@@ -25,26 +25,25 @@ import Type.Type (Type(VarN), Variable, mkFlexVar, mkFlexNumber)
25
25
26data Constraint
26data Constraint
27 = CTrue
27 = CTrue
28− | CSaveEnv
28+ | CSaveHeaders
29− | CEqual Error.Hint R.Region Type Type
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
30 | CAnd [Constraint]
33 | CAnd [Constraint]
31 | CLet [Scheme] Constraint
34 | CLet [Scheme] Constraint
32− | CInstance R.Region SchemeName Type
33
35
34
36
35
37
36-- SCHEMES
38-- SCHEMES
37
39
38
40
39−type SchemeName = N.Name
40−
41−
42data Scheme =
41data Scheme =
43 Scheme
42 Scheme
44− { _rigidQuantifiers :: [Variable]
43+ { _rigidVars :: [Variable]
45− , _flexibleQuantifiers :: [Variable]
44+ , _flexVars :: [Variable]
46− , _constraint :: Constraint
47 , _header :: Map.Map N.Name (A.Located Type)
45 , _header :: Map.Map N.Name (A.Located Type)
46+ , _constraint :: Constraint
48 }
47 }
49
48
50
49
@@ -54,42 +53,17 @@ data Scheme =
54
53
55monoscheme :: Map.Map N.Name (A.Located Type) -> Scheme
54monoscheme :: Map.Map N.Name (A.Located Type) -> Scheme
56monoscheme headers =
55monoscheme headers =
57− Scheme [] [] CTrue headers
56+ Scheme [] [] headers CTrue
58
57
59
58
60
59
61-- CONSTRAINT HELPERS
60-- CONSTRAINT HELPERS
62
61
63
62
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−
75-- ex qs constraint == exists qs. constraint
63-- ex qs constraint == exists qs. constraint
76ex :: [Variable] -> Constraint -> Constraint
64ex :: [Variable] -> Constraint -> Constraint
77−ex fqs constraint =
65+ex flexVars constraint =
78− CLet [Scheme [] fqs constraint Map.empty] CTrue
66+ CLet
79−
80−
81−forall :: [Variable] -> Constraint -> Constraint
82−forall rqs constraint =
83− CLet [Scheme rqs [] constraint Map.empty] CTrue
67+ [ Scheme [] flexVars Map.empty constraint
84−
68+ ]
85−
69+ CTrue
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)