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

S. Alexander Jacobson alex at alexjacobson.com
Tue Mar 1 21:52:59 EST 2005

For some reason, these two functions have different types.

   fun1 f (Left x)= Left (f x)
   fun1 _ r@(Right x) = Right x

   fun2 f (Left x) = Left (f x)
   fun2 _ r = r

Is there a way to rewrite fun2 so that f has type (a->b)?
In the general case, it seems wasteful to have to destruct and 
construct values just for type checking reasons, especially if your 
type has many more constructors than (Either a b).


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

More information about the Haskell-Cafe mailing list