on fbfa2ea help sign in
18 lines 964 B history raw
1module ProjectM36.DataTypes.Either where
2import ProjectM36.Base
3import ProjectM36.AtomFunction
4import qualified Data.HashSet as HS
5import qualified Data.Map as M
6
7eitherAtomType :: AtomType -> AtomType -> AtomType
8eitherAtomType tA tB = ConstructedAtomType "Either" (M.fromList [("a", tA), ("b", tB)])
9
10eitherTypeConstructorMapping :: TypeConstructorMapping
11eitherTypeConstructorMapping = [(ADTypeConstructorDef "Either" ["a", "b"],
12 [DataConstructorDef "Left" [DataConstructorDefTypeVarNameArg "a"],
13 DataConstructorDef "Right" [DataConstructorDefTypeVarNameArg "b"]])]
15eitherAtomFunctions :: AtomFunctions
16eitherAtomFunctions = HS.fromList [
17 compiledAtomFunction "isLeft" [eitherAtomType (TypeVariableType "a") (TypeVariableType "b"), BoolAtomType] $ \(ConstructedAtom dConsName _ _:_) -> pure (BoolAtom (dConsName == "Left"))
18 ]