[Haskell-cafe] user type declarations in Haskell

minh thu noteed at gmail.com
Thu Jun 22 07:12:36 EDT 2006

2006/6/22, Vladimir Portnykh <vportnykh at hotmail.com>:
> I am trying to define the following types
> data MyStringType a = String deriving (Eq, Ord, Show)
> data QADouble a = Double deriving (Eq, Ord, Show)
> data HType a = QADouble a| DDTraceType a deriving (Eq, Ord, Show)
> So HType can represent strings or doubles.
> later I want to do something like the following:
> let a1 =QADouble 1
> let a2 =QADouble 2
> let a3 = a1 + a2
a1 and a2 have type HType (not QADouble, nor Double).
GHC doesn't know how to use (+) on HType because (+) is meaningful
only for Num instances :
try to type ':t (+)' in ghci : it will give you the type of (+).
try to type also ':t a1'.

hope it helps,
vo minh thu

More information about the Haskell-Cafe mailing list