On 03/08/2010 10:45 PM, Wolfgang Jeltsch wrote:
> The point is, of course, that such conversions are not only possible for 
> binary operations but for arbitrary values and that these conversions are 
> done 
> by a single generic function conv. I don’t think it would be possible to 
> implement conv without generalized newtype deriving.
> 
> Any thoughts?
> 

Hi Wolfgang,

it's not exactly the same, but...

> import Control.Applicative
>
> newtype Wrapped a = Wrap a deriving Show
>
> instance Functor Wrapped where
>     fmap f (Wrap x) = Wrap $ f x
>
> instance Applicative Wrapped where
>     pure = Wrap
>     (Wrap f) <*> (Wrap x) = Wrap $ f x
>
> convBinOp :: (a -> a -> a) -> (Wrapped a -> Wrapped a -> Wrapped a)
> convBinOp op x y = pure op <*> x <*> y

Best regards,

Steffen
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to