1{-# LANGUAGE FlexibleInstances #-}
2module Type.Constrain.Pattern where
4import Control.Arrow (second)
5import qualified Control.Monad as Monad
6import qualified Data.Map as Map
8import qualified AST.Pattern as P
9import qualified AST.Variable as V
10import qualified Reporting.Annotation as A
11import qualified Reporting.Error.Type as Error
12import qualified Type.Constrain.Literal as Literal
13import qualified Type.Environment as Env
23constrain env (A.A region pattern) tipe =
25 equal patternError leftType rightType =
26 CEqual (Error.Pattern patternError) region leftType rightType
36 do c <- Literal.constrain env region lit tipe
37 return $ emptyFragment { typeConstraint = c }
40 do v <- variable Flexible
42 { typeEnv = Map.singleton name (rvar v)
45 equal (Error.PVar name) (varN v) tipe
49 do v <- variable Flexible
50 fragment <- constrain env p tipe
52 { typeEnv = Map.insert name (rvar v) (typeEnv fragment)
53 , vars = v : vars fragment
55 equal (Error.PAlias name) (varN v) tipe
56 /\ typeConstraint fragment
59 P.Data name patterns ->
60 do let stringName = V.toString name
62 (_kind, cvars, args, result) <-
63 Env.freshDataScheme env stringName
65 fragList <- Monad.zipWithM (constrain env) patterns args
66 let fragment = joinFragments fragList
68 { vars = cvars ++ vars fragment
70 typeConstraint fragment
71 /\ equal (Error.PData stringName) tipe result
76 mapM (\name -> (,) name <$> variable Flexible) fields
79 Map.fromList (map (second rvar) pairs)
82 Map.map (\v -> [A.drop v]) tenv
85 return (equal Error.PRecord tipe (record unannotatedTenv t))
89 , vars = map snd pairs
90 , 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