[Haskell-cafe] Forcing type conversion - probably FAQ(?)
Henning Thielemann
iakd0 at clusterf.urz.uni-halle.de
Wed Dec 1 12:57:25 EST 2004
On Wed, 1 Dec 2004, Dusan Kolar wrote:
> Hello,
>
> I'm trying to make work the following code (I'm using GHCi
> with flags -fglasgow-exts -fallow-undecidable-instances):
>
> infixl 6 :+, :-
> infixl 6 .+, .-
>
> data TMyExpr = TMyExpr :+ TMyExpr
> | TMyExpr :- TMyExpr
> | Val Int
> | Id String
What about introducing a single type parameter class which can convert
both Int and TMyExpr to TMyExpr?
(untested code follows)
class MkExpr a where
toExpr :: a -> TMyExpr
(.+) :: (MkExpr a, MkExpr b) => a -> b -> TMyExpr
(.+) x y = toExpr x :+ toExpr y
More information about the Haskell-Cafe
mailing list