[Haskell-cafe] how do I avoid excessive constructor application?
k.schupke at imperial.ac.uk
Wed Mar 2 10:13:24 EST 2005
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.
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?
> On Wed, 2 Mar 2005, Stefan Holdermans wrote:
>>> 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
> S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe