@@ -1,6 +1,23 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module Type.Type where
3+module Type.Type
4+ ( Variable
5+ , FlatType(..)
6+ , Type(..)
7+ , Descriptor(..)
8+ , Content(..)
9+ , Flex(..)
10+ , Super(..)
11+ , noRank
12+ , outermostRank
13+ , noMark
14+ , initialMark
15+ , (==>)
16+ , mkVar
17+ , mkNamedVar
18+ , toSrcType
19+ )
20+ where
421
522import Control.Monad (when)
623import Control.Monad.State.Strict (StateT, liftIO)
@@ -13,9 +30,6 @@ import Data.Text (Text)
1330
1431import qualified AST.Type as T
1532import qualified AST.Variable as Var
16−import qualified Reporting.Annotation as A
17−import qualified Reporting.Error.Type as Error
18−import qualified Reporting.Region as R
1933import qualified Type.UnionFind as UF
2034
2135
@@ -104,31 +118,6 @@ getVarNamesMark =
104118
105119
106120
107−-- CONSTRAINTS
108−
109−
110−data Constraint
111− = CTrue
112− | CSaveEnv
113− | CEqual Error.Hint R.Region Type Type
114− | CAnd [Constraint]
115− | CLet [Scheme] Constraint
116− | CInstance R.Region SchemeName Type
117−
118−
119−type SchemeName = Text
120−
121−
122−data Scheme =
123− Scheme
124− { _rigidQuantifiers :: [Variable]
125− , _flexibleQuantifiers :: [Variable]
126− , _constraint :: Constraint
127− , _header :: Map.Map Text (A.Located Type)
128− }
129−
130−
131−
132121-- TYPE HELPERS
133122
134123
@@ -181,49 +170,6 @@ toSuper name =
181170
182171
183172
184−-- CONSTRAINT HELPERS
185−
186−
187−monoscheme :: Map.Map Text (A.Located Type) -> Scheme
188−monoscheme headers =
189− Scheme [] [] CTrue headers
190−
191−
192−infixl 8 /\
193−
194−
195−(/\) :: Constraint -> Constraint -> Constraint
196−(/\) c1 c2 =
197− case (c1, c2) of
198− (CTrue, _) -> c2
199− (_, CTrue) -> c1
200− _ -> CAnd [c1,c2]
201−
202−
203−-- ex qs constraint == exists qs. constraint
204−ex :: [Variable] -> Constraint -> Constraint
205−ex fqs constraint =
206− CLet [Scheme [] fqs constraint Map.empty] CTrue
207−
208−
209−forall :: [Variable] -> Constraint -> Constraint
210−forall rqs constraint =
211− CLet [Scheme rqs [] constraint Map.empty] CTrue
212−
213−
214−exists :: (Type -> IO Constraint) -> IO Constraint
215−exists f =
216− do v <- mkVar Nothing
217− ex [v] <$> f (VarN v)
218−
219−
220−existsNumber :: (Type -> IO Constraint) -> IO Constraint
221−existsNumber f =
222− do v <- mkVar (Just Number)
223− ex [v] <$> f (VarN v)
224−
225−
226−
227173-- CONVERT TO SOURCE TYPES
228174
229175