1{-# LANGUAGE FlexibleInstances #-}
2module Type.Constrain.Pattern where
4import Control.Arrow (second)
5import Control.Applicative ((<$>))
6import qualified Control.Monad as Monad
7import qualified Data.Map as Map
9import qualified AST.Pattern as P
10import qualified AST.Variable as V
11import qualified Reporting.Annotation as A
12import qualified Type.Constrain.Literal as Literal
13import qualified Type.Environment as Env
23constrain env (A.A region pattern) tipe =
24 let (===) = CEqual region
31 do c <- Literal.constrain env region lit tipe
32 return $ emptyFragment { typeConstraint = c }
35 do v <- variable Flexible
37 { typeEnv = Map.singleton name (varN v)
39 , typeConstraint = varN v === tipe
43 do v <- variable Flexible
44 fragment <- constrain env p tipe
46 { typeEnv = Map.insert name (varN v) (typeEnv fragment)
47 , vars = v : vars fragment
48 , typeConstraint = varN v === tipe /\ typeConstraint fragment
51 P.Data name patterns ->
52 do (_kind, cvars, args, result) <-
53 Env.freshDataScheme env (V.toString name)
55 fragList <- Monad.zipWithM (constrain env) patterns args
56 let fragment = joinFragments fragList
58 { typeConstraint = typeConstraint fragment /\ tipe === result
59 , vars = cvars ++ vars fragment
63 do pairs <- mapM (\name -> (,) name <$> variable Flexible) fields
64 let tenv = Map.fromList (map (second varN) pairs)
65 c <- exists $ \t -> return (tipe === record (Map.map (:[]) tenv) t)
68 , vars = map snd pairs
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