
On Dec 30, 2007 2:43 PM, Jake McArthur
Really? This code doesn't even really make any sense to me. In order to be an instance of Bar, t has to already be an instance of Foo, implying that the function hi is already defined for t. What would the function in this example do?
Here's a different example: class Functor f where fmap :: (a -> b) -> f a -> f b class (Functor m) => Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a fmap = liftM In this case, any instance of Monad would automatically get a default Functor instance, which could presumably be overridden by an explicit Functor instance. The point is that (by default) you don't have to give the definition of *fmap* yourself. As AJB pointed out, the details can be subtle, so this sort of thing hasn't been implemented by anybody as far as I'm aware. Stuart