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 Reporting.Error.Type as Error
13import qualified Type.Constrain.Literal as Literal
14import qualified Type.Environment as Env
24constrain env (A.A region pattern) tipe =
26 (===) = CEqual Error.None region
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)
44 , typeConstraint = varN v === tipe
48 do v <- variable Flexible
49 fragment <- constrain env p tipe
51 { typeEnv = Map.insert name (rvar v) (typeEnv fragment)
52 , vars = v : vars fragment
53 , typeConstraint = varN v === tipe /\ typeConstraint fragment
56 P.Data name patterns ->
57 do (_kind, cvars, args, result) <-
58 Env.freshDataScheme env (V.toString name)
60 fragList <- Monad.zipWithM (constrain env) patterns args
61 let fragment = joinFragments fragList
63 { typeConstraint = typeConstraint fragment /\ tipe === result
64 , vars = cvars ++ vars fragment
68 do pairs <- mapM (\name -> (,) name <$> variable Flexible) fields
69 let tenv = Map.fromList (map (second rvar) pairs)
70 c <- exists $ \t -> return (tipe === record (Map.map (\v -> [A.drop v]) tenv) t)
73 , 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