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 =
25 let (===) = CEqual Error.None region
32 do c <- Literal.constrain env region lit tipe
33 return $ emptyFragment { typeConstraint = c }
36 do v <- variable Flexible
38 { typeEnv = Map.singleton name (varN v)
40 , typeConstraint = varN v === tipe
44 do v <- variable Flexible
45 fragment <- constrain env p tipe
47 { typeEnv = Map.insert name (varN v) (typeEnv fragment)
48 , vars = v : vars fragment
49 , typeConstraint = varN v === tipe /\ typeConstraint fragment
52 P.Data name patterns ->
53 do (_kind, cvars, args, result) <-
54 Env.freshDataScheme env (V.toString name)
56 fragList <- Monad.zipWithM (constrain env) patterns args
57 let fragment = joinFragments fragList
59 { typeConstraint = typeConstraint fragment /\ tipe === result
60 , vars = cvars ++ vars fragment
64 do pairs <- mapM (\name -> (,) name <$> variable Flexible) fields
65 let tenv = Map.fromList (map (second varN) pairs)
66 c <- exists $ \t -> return (tipe === record (Map.map (:[]) tenv) t)
69 , 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