1module Type.Constrain.Pattern where
3import Control.Arrow (second)
4import qualified Control.Monad as Monad
5import qualified Data.Map as Map
7import qualified AST.Pattern as P
8import qualified AST.Variable as V
9import qualified Reporting.Annotation as A
10import qualified Reporting.Error.Type as Error
11import qualified Type.Constrain.Literal as Literal
12import qualified Type.Environment as Env
17constrain :: Env.Environment -> P.Canonical -> Type -> IO Fragment
18constrain env (A.A region pattern) tipe =
20 equal patternError leftType rightType =
21 CEqual (Error.Pattern patternError) region leftType rightType
31 do c <- Literal.constrain env region lit tipe
32 return $ emptyFragment { typeConstraint = c }
35 do variable <- mkVar Nothing
37 { typeEnv = Map.singleton name (rvar variable)
40 equal (Error.PVar name) (VarN variable) tipe
44 do variable <- mkVar Nothing
45 fragment <- constrain env p tipe
47 { typeEnv = Map.insert name (rvar variable) (typeEnv fragment)
48 , vars = variable : vars fragment
50 equal (Error.PAlias name) (VarN variable) tipe
51 /\ typeConstraint fragment
54 P.Data name patterns ->
55 do let stringName = V.toString name
57 (_kind, cvars, args, result) <-
58 Env.freshDataScheme env stringName
60 fragList <- Monad.zipWithM (constrain env) patterns args
61 let fragment = joinFragments fragList
63 { vars = cvars ++ vars fragment
65 typeConstraint fragment
66 /\ equal (Error.PData stringName) tipe result
71 mapM (\name -> (,) name <$> mkVar Nothing) fields
74 Map.fromList (map (second rvar) pairs)
80 return (equal Error.PRecord tipe (record unannotatedTenv t))
84 , vars = map snd pairs
85 , typeConstraint = con
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list