Refactoring Semigroup/Monoid (was: instance Applicative Data.Map)

Tyson Whitehead twhitehead at gmail.com
Mon Nov 19 20:00:36 CET 2012


On November 19, 2012 12:25:57 Tyson Whitehead wrote:
> GHC 7.0.4 accepts this with FlexibleInstances and UndecidableInstances, but
> it seems to still have some issues (features?) as it overrides signatures
> 
>   *Main> :t pure
>   pure :: Monad f => a -> f a
> 
> unless you add other instances that are only at the lowel levels.  For
> example, adding Maybe at the Applicative level to the above [] instance
> 
>   instance Applicative Maybe where
>     applicative_apply (Just f) (Just x) = Just (f x)
>     applicative_apply _        _        = Nothing
>     applicative_map f (Just x) = Just (f x)
>     applicative_map _ _        = Nothing
>     applicative_pure x = Just x
> 
> gives
> 
>   *Main> :t pure
>   pure :: Monad f => a -> f a
>   *Main> :t Main.fmap
>   Main.fmap :: Applicative f => (a -> b) -> f a -> f b

Cut and paste mistake there.  That last bit should have been

  *Main> :t pure
  pure :: Applicative f => a -> f a
  *Main> :t Main.fmap
  Main.fmap :: Applicative f => (a -> b) -> f a -> f b

Adding a Functor only instance will make fmap resolve correctly.

Cheers!  -Tyson



More information about the Libraries mailing list