Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Alternative typeclass need to be a sub-class of Control.Applicative

Haskell provides a standard typeclass 'Alternative' that effectively provides the <|> operator for any type that is also an Applicative.

As I understand it Alternative is considered a Monoid on Applicative's, however the <|> operator seems to make complete sense in a lot of types that aren't Applicative Functors as well, and there doesn't need to be any specific dependency on the Applicative typeclass for it to work properly.

Is there a reason why Alternative needs to be a subclass of Applicative, and if so is there a standard typeclass to define similar functionality on non-applicative types?

like image 740
James Davies Avatar asked May 27 '15 11:05

James Davies


1 Answers

I think Alt from the semigroupoids package comes closest to being a 'standard' typeclass. https://hackage.haskell.org/package/semigroupoids-5.0.0.1/docs/Data-Functor-Alt.html#t:Alt

like image 85
Sjoerd Visscher Avatar answered Nov 16 '22 01:11

Sjoerd Visscher