Re: [Haskell-cafe] MonadPlus m => Maybe a -> m a

2012-07-28 Thread Alexander Solla
On Sat, Jul 28, 2012 at 8:00 AM, Thiago Negri wrote: > I'm solving this exercise: > > http://www.haskell.org/haskellwiki/All_About_Monads#Exercise_4:_Using_the_Monad_class_constraint > > I'm missing a function to transform a Maybe a into a MonadPlus m => m a. > I did search on Hoogle with no luck

[Haskell-cafe] MonadPlus m => Maybe a -> m a

2012-07-28 Thread Thiago Negri
I'm solving this exercise: http://www.haskell.org/haskellwiki/All_About_Monads#Exercise_4:_Using_the_Monad_class_constraint I'm missing a function to transform a Maybe a into a MonadPlus m => m a. I did search on Hoogle with no luck. There is no standard definition for the "g" function I'm defini

Re: [Haskell-cafe] MonadPlus versus Alternative

2011-10-30 Thread wren ng thornton
On 10/29/11 11:02 PM, Gregory Crosswhite wrote: Hey everyone, What is the difference between MonadPlus and Alternative? In my mind, it would make sense for the difference to be that the former provides "and" semantics (i.e., x `mplus` y means do both x and y) whereas the latter provides "or"

Re: [Haskell-cafe] MonadPlus versus Alternative

2011-10-30 Thread Sean Leather
On Sun, Oct 30, 2011 at 04:02, Gregory Crosswhite wrote: > So is there any difference between the interpretation of MonadPlus and > Alternative, or is the only difference between them that the former applies > to Monad whereas the latter applies to Applicative? > Somewhat OT, but this led me to p

Re: [Haskell-cafe] MonadPlus versus Alternative

2011-10-29 Thread David Barbour
MonadPlus is `or` semantics, as is Alternative. It does, indeed, reflect the Applicative/Monad difference. On Sat, Oct 29, 2011 at 8:02 PM, Gregory Crosswhite wrote: > Hey everyone, > > What is the difference between MonadPlus and Alternative? In my mind, it > would make sense for the difference

[Haskell-cafe] MonadPlus versus Alternative

2011-10-29 Thread Gregory Crosswhite
Hey everyone, What is the difference between MonadPlus and Alternative? In my mind, it would make sense for the difference to be that the former provides "and" semantics (i.e., x `mplus` y means do both x and y) whereas the latter provides "or" semantics (i.e., x <|> y means do x or y but not

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-03 Thread Edward Kmett
On Sun, May 2, 2010 at 4:23 AM, Sebastian Fischer < s...@informatik.uni-kiel.de> wrote: > Ideally, every MonadPlus instance would also be an Alternative instance and > every Alternative instance would be an instance of Monoid. You may find it > unfortunate that there are so many operations for the

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-03 Thread Edward Kmett
On Sat, May 1, 2010 at 7:11 PM, Sean Leather wrote: > I want to generalize a set of functions from lists to some functor type. I > require the following three operation types. > > f a > a -> f a > f a -> f a -> f a > Since f is a functor, FunctorPlus and Pointed together get you exactly th

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-02 Thread Sebastian Fischer
would you have any suggestions on a name for such a class or names for the methods? I'm afraid I don't. I'd like class Pointed t where point :: a -> t a class Monoid m where id :: m (.) :: m -> m -> m constraint Monoidy t = (Pointed t, Monoid (t a)) (although

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-02 Thread Sean Leather
On Sun, May 2, 2010 at 12:07, Sebastian Fischer wrote: > > On May 2, 2010, at 11:10 AM, Sean Leather wrote: > > Or should I make my own class? >> >> Then, there obviously won't be any instances for existing types other than >> your own (which might be a good or bad thing). You may want to do this

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-02 Thread Sebastian Fischer
On May 2, 2010, at 11:10 AM, Sean Leather wrote: Or should I make my own class? Then, there obviously won't be any instances for existing types other than your own (which might be a good or bad thing). You may want to do this, if you don't want to require either (>>=) or (<*>), which ma

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-02 Thread Sean Leather
On Sun, May 2, 2010 at 10:23, Sebastian Fischer wrote: > > On May 2, 2010, at 1:11 AM, Sean Leather wrote: > > I want to generalize a set of functions from lists to some functor type. >> [...] Should I choose MonadPlus and use these? [...] Or should I choose >> Alternative and use these? [...] >>

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-02 Thread Sebastian Fischer
On May 2, 2010, at 1:11 AM, Sean Leather wrote: I want to generalize a set of functions from lists to some functor type. [...] Should I choose MonadPlus and use these? [...] Or should I choose Alternative and use these? [...] There are some types that can be an instance of Alternative but

Re: [Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-01 Thread Mark Wassell
Check the laws that instances of MonadPlus and Alternative should comply with to help you make your decision. Cheers Mark Sean Leather wrote: I want to generalize a set of functions from lists to some functor type. I require the following three operation types. f a a -> f a f a -> f a

[Haskell-cafe] MonadPlus or Alternative or ...?

2010-05-01 Thread Sean Leather
I want to generalize a set of functions from lists to some functor type. I require the following three operation types. f a a -> f a f a -> f a -> f a Should I choose MonadPlus and use these? mzero return mplus Or should I choose Alternative and use these? empty pure (<|>) O

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Dan Piponi
Miguel said: > Well, that's the whole point of mathematics, isn't it? Abstraction is common to mathematics and computing. But in computing the abstraction often follows lines that seem obvious. For example a GUI library might have a Widget class and people can immediately identify various regions

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Miguel Mitrofanov
On 10 May 2008, at 00:43, Dan Piponi wrote: Andrew asked, ...so it's a kind of choice operator? Run all actions until you get to one that succeeds and return the result from that? The eternal bit of trickiness for Haskell is that type classes group often together things that people don't

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Dan Piponi
Andrew asked, > ...so it's a kind of choice operator? Run all actions until you get to one > that succeeds and return the result from that? The eternal bit of trickiness for Haskell is that type classes group often together things that people don't immediately see as similar - monads probably bei

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Nicolas Frisby
It sounds like the semantics of the MonadPlus methods are under-specified. I recall once writing a newtype wrapper to treat the same non-determinism monad with different mplus semantics, akin to cut versus backtracking. I think of MonadPlus as a less expressive version of msplit, from Backtrack

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Derek Elkins
On Fri, 2008-05-09 at 12:48 -0700, Bryan O'Sullivan wrote: > Andrew Coppin wrote: > > But here's a > > question: what is the purpose of the MonadPlus class? > > It gives you a way of working with monads as monoids. I find this description mostly useless. Monads form monoids without being MonadP

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Bryan O'Sullivan
Andrew Coppin wrote: > ...so it's a kind of choice operator? Run all actions until you get to > one that succeeds and return the result from that? In the context of Parsec, yes. In the grander scheme of things, the behaviour depends on whatever is appropriate for the particular monad you're work

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Derek Elkins
On Fri, 2008-05-09 at 12:47 -0700, David Roundy wrote: > On Fri, May 09, 2008 at 08:39:38PM +0100, Andrew Coppin wrote: > > OK, so I feel I understand monads fine. I regularly use Maybe, [] and > > IO, and I've even constructed a few monads of my own. But here's a > > question: what is the purpos

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Brandon S. Allbery KF8NH
On May 9, 2008, at 15:56 , Andrew Coppin wrote: Bryan O'Sullivan wrote: Andrew Coppin wrote: But here's a question: what is the purpose of the MonadPlus class? It gives you a way of working with monads as monoids. Consider a Parsec example: metasyntactic = text "foo" `mplus` text "ba

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Andrew Coppin
Bryan O'Sullivan wrote: Andrew Coppin wrote: But here's a question: what is the purpose of the MonadPlus class? It gives you a way of working with monads as monoids. Consider a Parsec example: metasyntactic = text "foo" `mplus` text "bar" `mplus` text "baz" You'll get back whichever

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Bryan O'Sullivan
Andrew Coppin wrote: > But here's a > question: what is the purpose of the MonadPlus class? It gives you a way of working with monads as monoids. Consider a Parsec example: metasyntactic = text "foo" `mplus` text "bar" `mplus` text "baz" You'll get back whichever one matched, in left-to-right-o

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread Rich Neswold
On Fri, May 9, 2008 at 2:39 PM, Andrew Coppin <[EMAIL PROTECTED]> wrote: > [In a somewhat unrelated question... I saw some code the other day that > used Either as if it were a monad. And yet, I don't see an instance given in > the standard libraries - even though there should be one. I can see Fu

Re: [Haskell-cafe] MonadPlus

2008-05-09 Thread David Roundy
On Fri, May 09, 2008 at 08:39:38PM +0100, Andrew Coppin wrote: > OK, so I feel I understand monads fine. I regularly use Maybe, [] and > IO, and I've even constructed a few monads of my own. But here's a > question: what is the purpose of the MonadPlus class? > > Clearly it defines a binary oper

[Haskell-cafe] MonadPlus

2008-05-09 Thread Andrew Coppin
OK, so I feel I understand monads fine. I regularly use Maybe, [] and IO, and I've even constructed a few monads of my own. But here's a question: what is the purpose of the MonadPlus class? Clearly it defines a binary operation over monadic values and an identity element for that operation. B

[Haskell-cafe] monadplus as monoid, safe?

2006-08-30 Thread Nicolas Frisby
I'm using the following code in some of my projects: newtype MonadPlusAsMonoid a = MPM { unMPM :: a } instance MonadPlus m => Monoid (MonadPlusAsMonoid (m a)) where mempty = MPM mzero MPM l `mappend` MPM r = MPM (l `mplus` r) Is there some sort of pitfall I'm not considering? It seems

Re: [Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread Daniel Fischer
Am Mittwoch, 2. Februar 2005 14:48 schrieb David Roundy: > On Wed, Feb 02, 2005 at 02:41:42PM +0100, Daniel Fischer wrote: > > Probably you haven't imported 'Control.Monad.Error', where the instance > > is defined. I did and all went well. > > Thanks, that did it. It's confusing that the instance

Re: [Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread David Roundy
On Wed, Feb 02, 2005 at 02:41:42PM +0100, Daniel Fischer wrote: > Probably you haven't imported 'Control.Monad.Error', where the instance is > defined. I did and all went well. Thanks, that did it. It's confusing that the instance is documented in Control.Monad. -- David Roundy http://www.darcs

RE: [Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread Simon Peyton-Jones
| David Roundy | Sent: 02 February 2005 13:18 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] MonadPlus instance for IO | | I'm sure I'm doing something stupid, but somehow ghc isn't recognizing the | existance of a MonadPlus instance for IO: | | DarcsIO.lhs:48: |

Re: [Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread Daniel Fischer
Am Mittwoch, 2. Februar 2005 14:17 schrieb David Roundy: > I'm sure I'm doing something stupid, but somehow ghc isn't recognizing the > existance of a MonadPlus instance for IO: > > DarcsIO.lhs:48: > No instance for (MonadPlus IO) > arising from use of `mplus' at DarcsIO.lhs:48 > In t

[Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread David Roundy
I'm sure I'm doing something stupid, but somehow ghc isn't recognizing the existance of a MonadPlus instance for IO: DarcsIO.lhs:48: No instance for (MonadPlus IO) arising from use of `mplus' at DarcsIO.lhs:48 In the definition of `foo': foo = (fail "aaack") `mplus` (fail "fo