Re: [Haskell-cafe] guards in applicative style

2012-09-17 Thread Ryan Ingram
Not exactly what you asked for, but... filter (uncurry somePredicate) $ (,) <$> list1 <*> list2 does the job. Using only applicative operations, it's impossible to affect the 'shape' of the result--this is the difference in power between applicative and monad. -- ryan On Wed, Sep 12, 20

Re: [Haskell-cafe] guards in applicative style

2012-09-12 Thread Ertugrul Söylemez
Brent Yorgey wrote: > However, guardA is not as useful as guard, and it is not possible to > do the equivalent of the example shown using a list comprehension with > a guard. The reason is that whereas monadic computations can make use > of intermediate computed values to decide what to do next,

Re: [Haskell-cafe] guards in applicative style

2012-09-12 Thread Brent Yorgey
Lorenzo is correct, but actually for the wrong reason. =) The *type* of guard is a historical accident, and the fact that it requires MonadPlus doesn't really tell us anything. Let's take a look at its implementation: guard :: (MonadPlus m) => Bool -> m () guard True = return

Re: [Haskell-cafe] guards in applicative style

2012-09-12 Thread Lorenzo Bolla
I'm no expert at all, but I would say "no". "guard" type is: guard :: MonadPlus m => Bool -> m () and "MonadPlus" is a monad "plus" (ehm...) mzero and mplus (http://en.wikibooks.org/wiki/Haskell/MonadPlus). On the other hand Applicative is "less" than a monad (http://www.haskell.org/haskellwiki/Ap

[Haskell-cafe] guards in applicative style

2012-09-12 Thread felipe zapata
Hi Haskellers, Suppose I have two list and I want to calculate the cartesian product between the two of them, constrained to a predicate. In List comprehension notation is just result = [ (x, y) | x <- list1, y <-list2, somePredicate x y ] or in monadic notation result = do x <- list1 y <- li