Opened 7 months ago

Closed 7 months ago

#8348 closed feature request (invalid)

Add Super-classes to libraries

Reported by: wvv Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Haskell community has a long discussion how to implement a superclasses into Haskell.

Now it is used default method. But it looks ugly!

But all their abilities are already implemented!

We need just 2 extensions: FlexibleInstances? and UndecidableInstances?

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}

instance Monad m => Applicative m where
    pure  = return
    (<*>) = ap
	
instance Monad m => Functor m where
    fmap = liftM

instance Monad m => Bind m where
    (>>-) = flip (>>=)
    B.join = M.join

this code is valid!

I've already defined 3 "superclassses" for Monad: Functor, Applicative and Bind!

"superclass' instances" have unique quality from Programming Patterns and typeclasses ideology: do not inherit, extend!

We could easily extend "superclasses" and make a lot of class' dependences.

We don't need to insert inside the class some ugliness like

  default return :: Applicative f => a -> f a
  return = pure

Next is much prettier!

instance Monoid m => Alternative m where
    (<|>) = mplus
    empty = mzero

We could even use it with Generic without any default:

class ToJSON a where
    toJSON   :: a -> Value

instance (Generic a, GToJSON (Rep a)) => ToJSON a where
    toJSON = genericToJSON defaultOptions

So, I suggest to made true "Applicative and Functor are superclasses of Monad" and add all necessary superclass' instances to base libraries.

Change History (1)

comment:1 Changed 7 months ago by monoidal

  • Resolution set to invalid
  • Status changed from new to closed

I'm afraid this is a bad idea, see http://stackoverflow.com/a/3216937. This issue notwithstanding, proposals to add new instances should be voted at the libraries mailing list.

Note: See TracTickets for help on using tickets.