Home

Awesome

Automatic H2010 to H201x Refactoring

Available on Hackage License BSD3 Build Status

Typeclass Refactoring

Monad-hierarchy

Haskell Report Definitions

Haskell 2010 defines only the Functor and Monad typeclasses:

class  Functor f  where
    fmap    :: (a -> b) -> f a -> f b

class  Monad m  where
    return  :: a -> m a

    (>>=)   :: m a -> (a -> m b) -> m b

    (>>)    :: m a -> m b -> m b
    m >> k  =  m >>= \_ -> k
    
    fail    :: String -> m a
    fail s  = error s

With Haskell 201x this evolves into

class  Functor f  where
    fmap    :: (a -> b) -> f a -> f b

class Functor f => Applicative f where
    -- | Lift a value.
    pure :: a -> f a

    -- | Sequential application.
    (<*>) :: f (a -> b) -> f a -> f b

    -- | Sequence actions, discarding the value of the first argument.
    (*>) :: f a -> f b -> f b
    (*>) = …

    -- | Sequence actions, discarding the value of the second argument.
    (<*) :: f a -> f b -> f a
    (<*) = …

class Applicative m => Monad m where
    -- | Monadic bind
    (>>=) :: forall a b. m a -> (a -> m b) -> m b

class Monad m => MonadFail m where
    -- | Invoked on pattern-failures in monadic binds
    fail :: String -> m a

-- Backward-compatible top-level alias bindings

(>>) :: Functor m => m a -> m b -> m b
(>>) = (*>)

return :: Applicative m => a -> m a
return = pure

GHC: Interim Haskell 2010 + Applicative definitions

There are multiple intermediate stages:

Rewrite rules

Converting from plain Haskell2010 to Haskell201x is simple:

TODO: Give rules based on AMP-migration-guide definitions