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 SourceSyntax.PrettyPrint
12import Text.PrettyPrint (render)
13import qualified SourceSyntax.Location as Loc
16import Type.Environment as Env
17import qualified Type.Constrain.Literal as Literal
20constrain :: Environment -> Pattern -> Type -> IO Fragment
21constrain env pattern tipe =
22 let span = Loc.NoSpan (render $ pretty pattern)
23 t1 === t2 = Loc.L span (CEqual t1 t2)
24 x <? t = Loc.L span (CInstance x t)
27 PAnything -> return emptyFragment
30 c <- Literal.constrain env span lit tipe
31 return $ emptyFragment { typeConstraint = c }
36 typeEnv = Map.singleton name (VarN v),
38 typeConstraint = VarN v === tipe
42 fragment <- constrain env p tipe
44 typeEnv = Map.insert name tipe (typeEnv fragment),
45 typeConstraint = name <? tipe /\ typeConstraint fragment
48 PData name patterns -> do
49 (kind, cvars, args, result) <- freshDataScheme env name
50 let msg = concat [ "Constructor '", name, "' expects ", show kind
51 , " argument", if kind == 1 then "" else "s"
52 , " but was given ", show (length patterns), "." ]
53 if length patterns /= kind then error msg else do
54 fragment <- Monad.liftM joinFragments (Monad.zipWithM (constrain env) patterns args)
56 typeConstraint = typeConstraint fragment /\ tipe === result,
57 vars = cvars ++ vars fragment
61 pairs <- mapM (\name -> (,) name <$> var Flexible) fields
62 let tenv = Map.fromList (map (second VarN) pairs)
63 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