-- * Constructor representations
Constr, -- abstract, instance of: Eq, Show
ConIndex, -- alias for Int, start at 1
- Fixity, -- instance of: Eq, Show
+ Fixity(..), -- instance of: Eq, Show
DataType, -- abstract, instance of: Show
-- * Constructing constructor representations
-- | Fixity of constructors
-data Fixity = NoFixity
- | PreFixity
- | InFixity
- deriving (Eq,Show)
+data Fixity = Prefix
+ | Infix -- Later: add associativity and precedence
+ deriving (Eq,Show)
-- | A package of constructor representations;
-- could be a list, an array, a balanced tree, or others.
-- | Make a representation for a datatype constructor
mkConstr :: ConIndex -> String -> Fixity -> Constr
+-- ToDo: consider adding arity?
mkConstr = DataConstr
-- | Make a package of constructor representations
-- define top-level definitions for representations.
--
-falseConstr = mkConstr 1 "False" NoFixity
-trueConstr = mkConstr 2 "True" NoFixity
+falseConstr = mkConstr 1 "False" Prefix
+trueConstr = mkConstr 2 "True" Prefix
boolDataType = mkDataType [falseConstr,trueConstr]
instance Data Bool where
-- Cons-lists are terms with two immediate subterms.
--
-nilConstr = mkConstr 1 "[]" NoFixity
-consConstr = mkConstr 2 "(:)" InFixity
+nilConstr = mkConstr 1 "[]" Prefix
+consConstr = mkConstr 2 "(:)" Infix
listDataType = mkDataType [nilConstr,consConstr]
instance Data a => Data [a] where
-- No surprises.
--
-nothingConstr = mkConstr 1 "Nothing" NoFixity
-justConstr = mkConstr 2 "Just" NoFixity
+nothingConstr = mkConstr 1 "Nothing" Prefix
+justConstr = mkConstr 2 "Just" Prefix
maybeDataType = mkDataType [nothingConstr,justConstr]
instance Data a => Data (Maybe a) where
-- No surprises.
--
-pairConstr = mkConstr 1 "(,)" InFixity
+pairConstr = mkConstr 1 "(,)" Infix
productDataType = mkDataType [pairConstr]
instance (Data a, Data b) => Data (a,b) where