1module Type.Constrain.Pattern where
3import Control.Arrow (second)
4import Control.Applicative ((<$>))
5import qualified Control.Monad as Monad
6import qualified Data.List as List
7import qualified Data.Maybe as Maybe
8import qualified Data.Map as Map
10import SourceSyntax.Pattern
11import qualified SourceSyntax.Location as Loc
14import Type.Environment as Env
15import qualified Type.Constrain.Literal as Literal
18constrain :: Environment -> Pattern -> Type -> IO Fragment
19constrain env pattern tipe =
21 t1 === t2 = Loc.L span (CEqual t1 t2)
22 x <? t = Loc.L span (CInstance x t)
25 PAnything -> return emptyFragment
28 c <- Literal.constrain env span lit tipe
29 return $ emptyFragment { typeConstraint = c }
34 typeEnv = Map.singleton name (VarN v),
36 typeConstraint = VarN v === tipe
40 fragment <- constrain env p tipe
42 typeEnv = Map.insert name tipe (typeEnv fragment),
43 typeConstraint = name <? tipe /\ typeConstraint fragment
46 PData name patterns -> do
47 (kind, cvars, args, result) <- freshDataScheme env name
48 let msg = concat [ "Constructor '", name, "' expects ", show kind
49 , " argument", if kind == 1 then "" else "s"
50 , " but was given ", show (length patterns), "." ]
51 if length patterns /= kind then error msg else do
52 fragment <- Monad.liftM joinFragments (Monad.zipWithM (constrain env) patterns args)
54 typeConstraint = typeConstraint fragment /\ tipe === result,
55 vars = cvars ++ vars fragment
59 pairs <- mapM (\name -> (,) name <$> var Flexible) fields
60 let tenv = Map.fromList (map (second VarN) pairs)
61 c <- exists $ \t -> return (tipe === record (Map.map (:[]) tenv) t)
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