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 equal patternError leftType rightType =
27 CEqual (Error.Pattern patternError) region leftType rightType
37 do c <- Literal.constrain env region lit tipe
38 return $ emptyFragment { typeConstraint = c }
41 do v <- variable Flexible
43 { typeEnv = Map.singleton name (rvar v)
46 equal (Error.PVar name) (varN v) tipe
50 do v <- variable Flexible
51 fragment <- constrain env p tipe
53 { typeEnv = Map.insert name (rvar v) (typeEnv fragment)
54 , vars = v : vars fragment
56 equal (Error.PAlias name) (varN v) tipe
57 /\ typeConstraint fragment
60 P.Data name patterns ->
61 do let stringName = V.toString name
63 (_kind, cvars, args, result) <-
64 Env.freshDataScheme env stringName
66 fragList <- Monad.zipWithM (constrain env) patterns args
67 let fragment = joinFragments fragList
69 { vars = cvars ++ vars fragment
71 typeConstraint fragment
72 /\ equal (Error.PData stringName) tipe result
77 mapM (\name -> (,) name <$> variable Flexible) fields
80 Map.fromList (map (second rvar) pairs)
83 Map.map (\v -> [A.drop v]) tenv
86 return (equal Error.PRecord tipe (record unannotatedTenv t))
90 , vars = map snd pairs
91 , typeConstraint = con
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