Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-27 Thread Job Vranish
You could test your instance using the checkers package on hackage (has quickcheck properties for common typeclasses) to see if it fulfills the applicative laws. But I'm not sure if it is acceptable to define applicative instances that don't match the monad instance. Does anyone know of libraries

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-27 Thread Iain Alexander
On 27 Aug 2009 at 07:48, Ralf Hinze wrote: \ x - (v = \ a - return ((u x) a)) x = { definition of = } \ x - (\ a - return ((u x) a)) (v x) x Something seems to have gone wrong here - shouldn't that be \x - (\y - (\a - return ((u x) a)) (v y) y) x = { beta } \x - (\a - return

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-27 Thread Jeremy Shaw
At Fri, 28 Aug 2009 01:01:09 +0100, I don't entirely follow what the OP's up to, so you may have a point, but it's far from clear. You're talking about the reader monad, whereas he's talking about the effects in the ReaderT-transformed monad. oops. Apparently I forgot to explictly state

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-27 Thread Jeremy Shaw
At Thu, 27 Aug 2009 10:47:43 -0400, Job Vranish wrote: I've often wanted an applicative instance for a datatype that didn't match the monad instance. It would be nice if there was a way to hide instances so that they could be redefined. Yeah, this is similar to the issue of multiple

[Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Jeremy Shaw
Hello, I have seen it said that all Monads are Applicative Functors because you can just do: instance (Monad f, Applicative f) = Applicative (ReaderT r f) where pure = return (*) = ap However, that instance for ReaderT does not exhibit the properties I was hoping for. By substitution

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Jeremy Shaw
Attached is as slight better test example which does not rely on the 'fail' method. Doesn't really change anything significant though. {-# LANGUAGE FlexibleContexts, FlexibleInstances #-} module Main where import Control.Applicative (Applicative((*), pure), ($)) import Control.Monad (Monad((=),

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Martijn van Steenbergen
Jeremy Shaw wrote: What I would prefer is: instance (Monad f, Applicative f) = Applicative (ReaderT r f) where pure a = ReaderT $ const (pure a) f * a = ReaderT $ \r - ((runReaderT f r) * (runReaderT a r)) Right. This doesn't only go for ReaderT, it already goes for

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Edward Kmett
On Wed, Aug 26, 2009 at 12:04 PM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Another example is parsing: I believe Doaitse's parsers allow more optimization if they are only used in applicative style (but I'm not sure of this). That is correct. When you glue together P_m's

Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Ralf Hinze
Hi Jeremy, I have seen it said that all Monads are Applicative Functors because you can just do: instance (Monad f, Applicative f) = Applicative (ReaderT r f) where pure = return (*) = ap However, that instance for ReaderT does not exhibit the properties I was hoping for. OK,