on ea77dcf help sign in
elk/src/Type/Constraint.hs
69 lines 1.4 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Type.Constraint
4 ( Constraint(..)
5 , ex
6 , Scheme(..)
7 , monoscheme
8 )
9 where
12import qualified Data.Map.Strict as Map
14import qualified AST.Canonical as Can
15import qualified Elm.Name as N
16import qualified Reporting.Annotation as A
17import qualified Reporting.Error.Type as Error
18import qualified Reporting.Region as R
19import Type.Type (Type, Variable)
23-- CONSTRAINTS
26data Constraint
27 = CTrue
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
33 | CAnd [Constraint]
34 | CLet [Scheme] Constraint
38-- SCHEMES
41data Scheme =
42 Scheme
43 { _rigidVars :: [Variable]
44 , _flexVars :: [Variable]
45 , _header :: Map.Map N.Name (A.Located Type)
46 , _constraint :: Constraint
47 }
51-- SCHEME HELPERS
54monoscheme :: Map.Map N.Name (A.Located Type) -> Scheme
55monoscheme headers =
56 Scheme [] [] headers CTrue
60-- CONSTRAINT HELPERS
63-- ex qs constraint == exists qs. constraint
64ex :: [Variable] -> Constraint -> Constraint
65ex flexVars constraint =
66 CLet
67 [ Scheme [] flexVars Map.empty constraint
68 ]
69 CTrue