[Haskell-beginners] Trying to prove Applicative is superclass of Functor, etc
Silent Leaf
silent.leaf0 at gmail.com
Sat Apr 30 19:14:03 UTC 2016
I think I got what exactly was the change of ghc 7.10. basically it only
adds a constraint Applicative on the Monad class, and same with
Functor/Applicative. it doesn't automatically write implied instances, but
just forces one to actually write said instances of those superclasses. In
short you can't anymore make monads without making Applicatives,
"beforehand" (even though order is not important).
In my opinion it's pretty shitty. I totally agree that it's (partially)
more mathematically correct, and that's great. yet in my opinion, given
superclasses can always be derived from their subclasses, it should be
mathematically automatic to prove superclass instances by proving any
subclass thereof. Otherwise it's forcing the programmer to do even more
possibly-useless work (we don't always need applicative and functors for
every use of a new monad, do we?) without gaining anything in return but a
very abstract idea of "correctness". in short i think if they wanted
mathematical correctness they should have added automatic instanciation of
superclasses, with possibility to override the default definitions, like
they do so with some superfluous methods.
Not that write functors or applicative functor instances is actually
heavywork, of course, thankfully.
I kinda wonder, can we define Applicative methods in function of Monad
methods, even though those latter can only be type-valid if the Applicative
instance is already created and checked? or maybe we can write a
class-neutral version (without constraints)?
Say something like that:
> -------- version one, with constraints
> mkAp :: (Monad m, Applicative m) => m (a -> b) -> m a -> m b
> mkAp mf ma = mf >>= \f -> ma >>= \a -> return $ f a
> -- (not entirely sure on the necessary constraints of this type
signature...)
> instance Functor f => Applicative f where
> <*> = mkAp
> -- the value is automatically different depending on the instance
right?
> pure = return
course, I'm pretty sure mkAp == ap, aka the monad equivalent of (<*>) is
automatically defined at instanciation of the monad. But i think to
remember it uses fmap, and in theory the idea is that neither instances of
Functor or Applicative would yet exist. All depends on the possibility to
define a superclass instance in terms of a subclass instance.
> -------- version two, without class -- can we use type constructors in
signature without classes?
> mkAp :: (**signature of bind**) -> (a -> m a) -> (( m (a -> b) -> m a ->
m b ))
> mkAp bind return mf ma = ... -- defined in terms of those given
class-independent functions
I'mma check myself but if it fails i wonder if anyone knows a way around?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160430/769fd1dc/attachment.html>
More information about the Beginners
mailing list