
Something like: class Coerce a b where coerce :: a -> b The class must be in a separate file from the instance so that the compiler does not determine that a == b for all instances. instance Coerce a a where coerce = id If it turns out the left and right types do not match, you get a "no instance of coerce for ..." error. Keean. S. Alexander Jacobson wrote:
I'd like to do this sort of thing with types other than Either. Is there a generic safe coerce function?
-Alex-
On Wed, 2 Mar 2005, Stefan Holdermans wrote:
Lemmih,
And you can "fix" it with some unsafeCoerce# magic. (:
Actually, as I pointed out, the required coercion in perfectly safe, though not implicit:
coerceRight :: Either a b -> Either c b coerceRight (Right b) = Right b
Regards,
Stefan
______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe