@@ -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 ]