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 evoh...@gmail.com 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.

 There is no standard definition for the g function I'm defining?


g :: (MonadPlus m) = Maybe a - m a
 g Nothing = mzero
 g (Just a) = return a


I doubt there is a standard named function for this, since conversions
between monads are typically not unique and there are lots and lots of
pairs of monads you can convert between.

You can define g in terms of Data.Maybe.maybe as:

g = maybe mzero return
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 playing with ConstraintKinds:

https://github.com/spl/sandbox/blob/master/ConstraintKindsAlternativeMonadPlus.lhs

Regards,
Sean
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 semantics (i.e., x|  y means do x or y but not 
both).  However, when I look at the instances defined for List I see that it is exactly the same as 
MonadPlus.


As other's've mentioned, they both have or semantics and it's just an 
artifact of the Monad/Applicative split. However, an additional note.


For lists or sets, the mplus/(|) functions could be interpreted as 
both and and or semantics, depending on what you think lists are. If 
you think of them as a collection of multiple answers, then 
concatenating/unioning is colloquially regarded as saying I have xs and 
ys. However, if you think of them as giving a non-deterministic answer, 
then the concatenation/union should be regarded as saying you can chose 
the xs or the ys, which is closer to the logical interpretation of union 
as disjunction.


I guess my point is that the notion of and isn't especially 
well-defined. At the very least there are three different notions of 
and. We have the andThen notion which corresponds to monadic bind, 
probabilistic conjunction, and Sigma types. We have the andAlso notion 
which corresponds to unions conceived of as nondeterminisms, also covers 
the linear conjunction which only lets you take one of the projections, 
and is the one involved with the idea of anding two functions with 
(+++). And we have the bothAnd notion which corresponds to Cartesian 
products, logical conjunction, the linear conjunction which lets you 
take both projections, and the notion of anding two functions with (***).


--
Live well,
~wren

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
gcrosswh...@gmail.comwrote:

 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 both).
  However, when I look at the instances defined for List I see that it is
 exactly the same as MonadPlus.

 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?

 Also, along similar lines, why does MonadPlus exist when it is essentially
 just a special case of Monoid?  (That is, any MonadPlus instance could be
 equivalently cast as a Monoid instance.)

 Thanks!
 Greg

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-05-03 Thread Edward Kmett
On Sat, May 1, 2010 at 7:11 PM, Sean Leather leat...@cs.uu.nl 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 the
subset of functionality that you want. Whether or not category-extras can be
considered a light weight dependency on the other hand is another thing
entirely. ;)

-Edward Kmett
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 same thing but until
 the (Applicative/Monad) class hierarchy is refactored, we have to live with
 it.


Sadly there is at least one MonadPlus/Alternative and Monoid instance that
differs:

Maybe

The Monoid instance for Maybe is the lifting of a semigroup into a monoid by
adding an identity element, but unfortunately, it does so rather poorly as
there is no semigroup class that it can assume for its argument, and so it
lifts a monoid into a monoid, while avoiding the use of the underlying
definition for mempty. =/

So there is no path forward that doesn't change the meaning of existing
programs that makes the Alternative and Monoid instances agree on all
Applicatives.

-Edward Kmett
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 not of  
MonadPlus (because they are not a monad but an applicative functor).  
Hence, if you choose Alternative, then your functions are more  
generally applicable. In practice, there may be instances of MonadPlus  
for wich their authors chose not to provide an Alternative instance  
and your functions then could not be applied to those types. But every  
MonadPlus instance `m` can be made an Alternative instance by declaring


instance Functor m where
  fmap = liftM

instance Applicative m where
  pure = return
  (*) = ap

instance Alternative m where
  empty = mzero
  (|) = mplus

The laws required by MonadPlus imply the laws required by theses  
instances.



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 may  
not be supported for reasonable instances of your own class.



Or is there another option?


If you have functions that do not need return/pure you can also use a  
Monoid constraint on those functions and replace empty/mzero with  
mempty and |/mplus with mappend. Again, those functions share the  
same laws.


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 same thing but until the (Applicative/Monad) class hierarchy  
is refactored, we have to live with it.


Sebastian


--
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 may not be supported for reasonable instances of your own class.


I don't really want to do this option, because it increases the  
understanding overhead needlessly, I think. Everything else that is  
provided by Applicative/Monad doesn't matter. I require only the  
three operations above and do not disallow extra operations.


By not making your own class, you prohibit types that do not support  
* (or =). That's fine, but an additional burden to instance  
writers. By not listing extra operations in your own class you would  
not disallow them. You require them by not making your own class  
without them.


But still, your wish to reuse existing classes may be a fine reason to  
impose an additional burden.


Sebastian

--
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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, if
 you don't want to require either (=) or (*), which may not be supported
 for reasonable instances of your own class.

 I don't really want to do this option, because it increases the
 understanding overhead needlessly, I think. Everything else that is provided
 by Applicative/Monad doesn't matter. I require only the three operations
 above and do not disallow extra operations.


 By not making your own class, you prohibit types that do not support *
 (or =). That's fine, but an additional burden to instance writers. By not
 listing extra operations in your own class you would not disallow them. You
 require them by not making your own class without them.


Understood and agreed. Having my own class would be the most flexible in
what it allows and disallows.

But still, your wish to reuse existing classes may be a fine reason to
 impose an additional burden.


There is an additional maintenance burden that I've recently become aware
of, considering I haven't done a very good job of maintaining my own code.
;) To use my own class, I should reasonably provide instances for everything
that I possibly can. This would include (at least) lists, Maybe,
WrappedAlternative, and WrappedMonadPlus.

Who knows? I may change my mind in a while. In that case, would you have any
suggestions on a name for such a class or names for the methods? ;)

class C f where
  zero :: f a
  one :: a - f a
  append :: f a - f a - f a

Sean
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 I'm not a big fan of the involved names except for the  
Monoid class)


But the above is currently impractical for various reasons ;) (more  
than those listed in [1]).


Sebastian

[1] Haskell Type Constraints Unleashed
 http://www.cs.kuleuven.be/~toms/Research/papers/constraint_families.pdf

--
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 - f a

Should I choose MonadPlus and use these?

  mzero
  return
  mplus

Or should I choose Alternative and use these?

  empty
  pure
  (|)

Or should I make my own class? Or is there another option?

Thanks,
Sean


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
  


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 operation over monadic values and an 
 identity element for that operation. But... what is this supposed to 
 *do*? (For example, () has an almost identical signature to mplus. But 
 presumably they don't both do the same thing...) What functionallity is 
 this supposed to give you?

MonadPlus is a crude way of achieving the catching of exceptional cases,
and you should think of mplus as being equivalent to (catch . const).  The
trouble is that MonadPlus doesn't provide any mechanism for finding out
what went wrong, so I've only ever found it useful when using the Maybe
monad (which itself has no way of identifying what went wrong).

 [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 Functor (Either a), but not Monad (Either a) or even Monad (Either 
 String)...]

I am pretty certain that there is a monad instance for Either, but also
don't know where it's defined.
-- 
David Roundy
Department of Physics
Oregon State University
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 Functor
 (Either a), but not Monad (Either a) or even Monad (Either String)...]


It's used in the Error Monad.

-- 
Rich

JID: [EMAIL PROTECTED]
LOI: https://www.google.com/reader/shared/00900594587109808626
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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-order, or mzero
(a parse failure) if all of them fail.

b
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 one matched, in left-to-right-order, or mzero
(a parse failure) if all of them fail.
  


...so it's a kind of choice operator? Run all actions until you get to 
one that succeeds and return the result from that?


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 bar `mplus` text baz

You'll get back whichever one matched, in left-to-right-order, or  
mzero

(a parse failure) if all of them fail.



...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 monadic guise that's how it's usually used, yes (since monoids  
like (+) are not generally all that useful as monads; (++) (list  
monad) and (.) (Monad ((-) r)) might be, though).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 purpose of the MonadPlus class?
  
  Clearly it defines a binary operation over monadic values and an 
  identity element for that operation. But... what is this supposed to 
  *do*? (For example, () has an almost identical signature to mplus. But 
  presumably they don't both do the same thing...) What functionallity is 
  this supposed to give you?
 
 MonadPlus is a crude way of achieving the catching of exceptional cases,
 and you should think of mplus as being equivalent to (catch . const).  The
 trouble is that MonadPlus doesn't provide any mechanism for finding out
 what went wrong, so I've only ever found it useful when using the Maybe
 monad (which itself has no way of identifying what went wrong).

MonadPlus is a crude way of doing that, but that isn't the motivating
example of MonadPlus, indeed, that arguably shouldn't be a MonadPlus
instance.  Cale Gibbard suggests (perhaps not originally) splitting
MonadPlus into MonadPlus (and MonadZero) and MonadOrElse.  They'd have
essentially the same operations, but would be intended to satisfy
different laws.  Maybe, Either e, IO are better instances of MonadOrElse
while [], Parser, LogicT, other non-determinism, parser, or concurrency
monads would more appropriately be MonadPlus.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 working in.

So, for example, mplus for lists is (++) and mzero is [], which is quite
a different set of behaviours from the Parsec case.  Usually, you can
rely on MonadPlus behaving like a monoid.  There are occasional
exceptions, which is a mite upsetting.

http://www.haskell.org/haskellwiki/MonadPlus

b
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 MonadPlus.

instance Monad m = Monoid (m ()) where
mempty = return ()
mappend = ()

You can form monoids out of Kleisli arrows,

instance Monad m = Monoid (a - m a) where
mempty = return
mappend = (=)

You could form monads into a monoid in another way,

instance (Monad m, Monoid a) = Monoid (m a)
mempty = return mempty
mappend = liftM2 mappend

So It gives you a way of working with monads as monoids. is
significantly underspecified and doesn't actually say what MonadPlus
means, let alone what it is intended for.

A more interesting statement in that vein is:
It gives you a way of working with monads as (distributive) near-rigs.

This statement does actually encode some (all?) of the intended meaning
of MonadPlus, e.g. mzero is intended to be a zero of () beyond simply
being a unit for mplus.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

  Backtracking, Interleaving, and Terminating Monad Transformers
  The Functional Pearl paper by Oleg Kiselyov, Chung-chieh Shan,
Daniel P. Friedman and Amr Sabry. ICFP 2005.

Is that an over-simplification?

On Fri, May 9, 2008 at 3:12 PM, Bryan O'Sullivan [EMAIL PROTECTED] wrote:
 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 working in.

 So, for example, mplus for lists is (++) and mzero is [], which is quite
 a different set of behaviours from the Parsec case.  Usually, you can
 rely on MonadPlus behaving like a monoid.  There are occasional
 exceptions, which is a mite upsetting.

 http://www.haskell.org/haskellwiki/MonadPlus

b
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 being the best example. So it's probably best not to
immediately try to find an all-encompassing summary of MonadPlus like
a kind of choice operator but instead concentrate on the definition.
The key thing is the line

 mplus :: m a - m a - m a

You can combine two m a's together with a binary operation to get
another m a. Absolutely any binary operation (with an identity) that
fits the rather lax laws that come with MonadPlus will do. Depending
on context mplus might mean either/or, or and, or this first, or
else that or something entirely different that nobody here has
anticipated yet. For each monad m, just try to think about how you
might combine a pair of m a's and what might serve as an identity.
--
Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 immediately see as similar -
monads probably being the best example.


Well, that's the whole point of mathematics, isn't it? Mathematics is  
just a way to name different things with one word (opposed to  
philosophy, which is a way to name the same thing with different words).

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 of the screen with Widgets and know that when
they want a new kind of device in their GUI it's time to define a
widget. Although the Widget class may be technically defined by the
interface it exposes, in practice people just think a gadget that can
appear on the screen. Even someone who has never programmed can
probably quickly guess what kinds of things correspond to instances of
the Widget class.

But mathematics is full of abstractions that aren't like this. Times
modulo 24 hours and the way a closed loop can travel around a knot
both form a group. The thing they have in common is that there's a
binary operation with identity and inverses. Sometimes it can be more
confusing to try to find a snappy English phrase that sums them up
without restating the definition. Many common Haskell type classes
lean towards the latter kind of abstraction.
--
Dan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] MonadPlus instance for IO

2005-02-02 Thread Simon Peyton-Jones
that instance seems to be only in Control.Monad.Error in the 'mtl'
package.  It's not in the standard base package.

You may need to import an mtl module to tell GHC to look there.

Simon

| -Original Message-
| From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
| 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:
| No instance for (MonadPlus IO)
|   arising from use of `mplus' at DarcsIO.lhs:48
| In the definition of `foo':
| foo = (fail aaack) `mplus` (fail foobar)
| 
| Any idea what I'm doing wrong? I'm using
| 
| $ ghc --version
| The Glorious Glasgow Haskell Compilation System, version 6.2.2
| 
| packaged for debian.
| --
| David Roundy
| http://www.darcs.net
| ___
| Haskell-Cafe mailing list
| Haskell-Cafe@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 is documented in
 Control.Monad.

Yes, very confusing, but what could one do?
Maybe urge people to mention instance declarations in the module description,
so from the absence of one, you are led to look elsewhere.
But that might make descriptions unduly large sometimes.

Daniel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe