elm/compiler/Type/Fragment.hs
Evan Czaplicki 9dd5dff279 Make AST more general and try to give its phases better names
Also change the constructors for the Pattern ADT
2014-02-10 00:17:33 +01:00

27 lines
767 B
Haskell

module Type.Fragment where
import qualified Data.List as List
import qualified Data.Map as Map
import Type.Type
import SourceSyntax.Pattern
import SourceSyntax.Annotation (noneNoDocs)
data Fragment = Fragment
{ typeEnv :: Map.Map String Type
, vars :: [Variable]
, typeConstraint :: TypeConstraint
} deriving Show
emptyFragment = Fragment Map.empty [] (noneNoDocs CTrue)
joinFragment f1 f2 = Fragment
{ typeEnv = Map.union (typeEnv f1) (typeEnv f2)
, vars = vars f1 ++ vars f2
, typeConstraint = typeConstraint f1 /\ typeConstraint f2
}
joinFragments = List.foldl' (flip joinFragment) emptyFragment
toScheme fragment =
Scheme [] (vars fragment) (typeConstraint fragment) (typeEnv fragment)