[Haskell-cafe] how do I avoid excessive constructor application?

S. Alexander Jacobson alex at alexjacobson.com
Wed Mar 2 09:20:15 EST 2005


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?

-Alex-

______________________________________________________________
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com

On Wed, 2 Mar 2005, Henning Thielemann wrote:

>
> On Wed, 2 Mar 2005, Ben Lippmeier wrote:
>
>> You can play games with the type checker to force them to have the same
>> type without changing the "meaning" of your function.
>>
>> fun1' f (Left x)    = if True then Left (f x) else Left x
>
> Left (f x) `asTypeOf` Left x
>
> ?
>



More information about the Haskell-Cafe mailing list