I am learning Haskell recently. And I keep wondering if I can use literal number as data constructor, like Integer,Int, Word do. For example, for the following code,
data MyBool = Zero | One
deriving(Bounded, Eq, Show, Enum)
toBool Zero = False
toBool One = True
fromBool False = Zero
fromBool True = One
myAnd = ff (&&) toBool fromBool
myOr = ff (||) toBool fromBool
ff pp fp pf x y= pf $ pp (fp x) (fp y)
what I want to do is replace Zero with 0, One with 1, so that I can use something like : myAnd (1::MyBool) (0::MyBool).
I did look into the source code of ghc, I find something like:
data Int = GHC.Types.I# GHC.Prim.Int#
data Word = GHC.Types.W# GHC.Prim.Word#
And as I researched Int# is 'unbox type', which must be the key that enabled them to use literal number as data constructor.
So how could I make my type use literal number as data constructor like Int and Word do?
(Don't hesitate to ask if the question's ambiguous.)