on 8cfc3ee help sign in
29 lines 1.4 kB history raw
1module ProjectM36.DataTypes.Maybe where
2import ProjectM36.Base
3import ProjectM36.DataTypes.Primitive
4import qualified Data.HashSet as HS
5import qualified Data.Map as M
8maybeAtomType :: AtomType -> AtomType
9maybeAtomType arg = ConstructedAtomType "Maybe" (M.singleton "a" arg)
11maybeTypeConstructorMapping :: TypeConstructorMapping
12maybeTypeConstructorMapping = [(ADTypeConstructorDef "Maybe" ["a"],
13 [DataConstructorDef "Nothing" [],
14 DataConstructorDef "Just" [DataConstructorDefTypeVarNameArg "a"]])
15 ]
17maybeAtomFunctions :: AtomFunctions
18maybeAtomFunctions = HS.fromList [
19 AtomFunction {
20 atomFuncName ="isJust",
21 atomFuncType = [maybeAtomType AnyAtomType, BoolAtomType],
22 atomFuncBody = AtomFunctionBody Nothing $ \((ConstructedAtom dConsName _ _):_) -> BoolAtom (dConsName /= "Nothing")
23 },
24 AtomFunction {
25 atomFuncName = "fromMaybe",
26 atomFuncType = [AnyAtomType, maybeAtomType AnyAtomType, AnyAtomType], -- this really should be more specific, but we don't have type checker handling for this yet
27 atomFuncBody = AtomFunctionBody Nothing $ \(defaultAtom:(ConstructedAtom dConsName _ (atomVal:_)):_) -> if atomTypeForAtom defaultAtom /= atomTypeForAtom atomVal then error "poop" else if dConsName == "Nothing" then defaultAtom else atomVal
28 }
29 ]