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
22constrain env (A.A region pattern) tipe =
24 equal patternError leftType rightType =
25 CEqual (Error.Pattern patternError) region leftType rightType
35 do c <- Literal.constrain env region lit tipe
36 return $ emptyFragment { typeConstraint = c }
39 do variable <- mkVar Nothing
41 { typeEnv = Map.singleton name (rvar variable)
44 equal (Error.PVar name) (VarN variable) tipe
48 do variable <- mkVar Nothing
49 fragment <- constrain env p tipe
51 { typeEnv = Map.insert name (rvar variable) (typeEnv fragment)
52 , vars = variable : vars fragment
54 equal (Error.PAlias name) (VarN variable) tipe
55 /\ typeConstraint fragment
58 P.Data name patterns ->
59 do let stringName = V.toString name
61 (_kind, cvars, args, result) <-
62 Env.freshDataScheme env stringName
64 fragList <- Monad.zipWithM (constrain env) patterns args
65 let fragment = joinFragments fragList
67 { vars = cvars ++ vars fragment
69 typeConstraint fragment
70 /\ equal (Error.PData stringName) tipe result
75 mapM (\name -> (,) name <$> mkVar Nothing) fields
78 Map.fromList (map (second rvar) pairs)
84 return (equal Error.PRecord tipe (record unannotatedTenv t))
88 , vars = map snd pairs
89 , 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