Ticket #113 (new modification)

Opened 2 years ago

Joined-Up Classes

Reported by: ashley@semantic.org Assigned to: none
Priority: major Milestone:
Component: Proposal Version:
Keywords: Cc:
Impact: normal Adopt:
Topic: Libraries

Description

Currently the Monad class is not a subclass of Functor. It should be.

Proposal:

1. Add this:

  class (Functor f) => Idiom f where -- or Applicative
    return :: a -> f a
    ap :: f (a -> b) -> f a -> f b
    (>>) :: f a -> f b -> f b
    fa >> fb = ap (fmap (const id) fa) fb

(See also Control.Applicative in GHC HEAD.)

2. Replace existing Monad class with this:

  class (Idiom m) => Monad m where
    (>>=) :: m a -> (a -> m b) -> m b
    fail :: String -> m a
    fail = error

3. Remove existing "ap", generalise and remove redundant Prelude functions as appropriate.