on master help sign in
add fromMaybe function for Maybe types
commit79f2d4270648947989f4c27b979d3e82ef1fbde4 authorAgentM <agentm@themactionfaction.com> dateTue 20 Sep 2016, 22:52 (10 years ago) parent8b7e4e4
1 file changed+9−2
src/lib/ProjectM36/DataTypes/Maybe.hs+9−2
src/lib/ProjectM36/DataTypes/Maybe.hs+9−2
@@ -1,8 +1,10 @@
11module ProjectM36.DataTypes.Maybe where
22import ProjectM36.Base
3+import ProjectM36.DataTypes.Primitive
34import qualified Data.HashSet as HS
45import qualified Data.Map as M
56
7+
68maybeAtomType :: AtomType -> AtomType
79maybeAtomType arg = ConstructedAtomType "Maybe" (M.singleton "a" arg)
810
@@ -17,6 +19,11 @@ maybeAtomFunctions = HS.fromList [
1719 AtomFunction {
1820 atomFuncName ="isJust",
1921 atomFuncType = [maybeAtomType AnyAtomType, BoolAtomType],
20− atomFuncBody = AtomFunctionBody Nothing $ \((ConstructedAtom dConsName _ _):_) -> BoolAtom (dConsName == "Nothing")
21− }
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+ }
2229 ]