[Haskell-cafe] how do I avoid excessive constructor application?
Lemmih
lemmih at gmail.com
Wed Mar 2 09:39:42 EST 2005
On Wed, 2 Mar 2005 09:20:15 -0500 (Eastern Standard Time), S.
Alexander Jacobson <alex at alexjacobson.com> wrote:
> My point was that this code seems excessively complex:
>
> fun::(a->a1)->(Either a b)->Either a1 b
> fun f (Left x) = Left (f x)
> fun _ r@(Right x)= Right x
>
> I'd like to avoid the destruction and construction in the third line
> by replacing the right hand side with r. However, the typechecker
> then claims my type is wrong. How do I fix that?
In your example, 'r' has type "Either a b" which doesn't match "Either
a1 b". And you can "fix" it with some unsafeCoerce# magic. (:
--
Friendly,
Lemmih
More information about the Haskell-Cafe
mailing list