3 ms·
Typeclasses provide nothing but convenience there (see [1] for instance). The real power comes from the Algebraic Data Types which are intact. [1] http://www.h
by tel 13y ago
Typeclasses provide nothing but convenience there (see [1] for instance). The real power comes from the Algebraic Data Types which are intact.
[1] http://www.haskellforall.com/2012/05/scrap-your-type-classes.html http://www.haskellforall.com/2012/05/scrap-your-type-classes...
- colanderman 13y agoI don't see how that mechanism provides subtyping (which typeclasses do)? Last I checked Haskell's structures weren't structurally typed.
- tel 13y agoYou could do it like in Agda, data ApplicativeI f = AI { pure :: forall a. a -> f a , ap :: forall a b. f (a -> b) -> f a -> f b , _FunctorI :: FunctorI f } data MonadI m = AI { bind :: forall a b. (a -> m b) -> m a -> m b , _ApplicativeI :: ApplicativeI m } return :: _MonadI m -> a -> m a return (MonadI { _ApplicativeI = ApplicativeI { pure = fn } }) = fn
- colanderman 13y agoAlmost, but that's not extensible: I can't declare some new typeclass Foo and then declare that every x s.t. Monad x is also Foo x without editing the definition of Monad.
- deleted 13y ago[deleted]
- tome 13y agoPersonally I wouldn't want to do the instance plumbing by hand.