On Thu, 02 Oct 2003 14:57:22 +0200, Juanma Barranquero [EMAIL PROTECTED] wrote:
data Accum s a = Ac [s] a
instance Monad (Accum s) where
return x = Ac [] x
Ac s1 x = f = let Ac s2 y = f x in Ac (s1++s2) y
output :: a - Accum a ()
output x = Ac [x] ()
After trying this one,
I have an extremely-newbie question about monads and how to interpret
the monadic laws; I asked that same question yesterday on IRC and the
answers were interesting but non-conclusive (to me anyway).
I'm trying to learn monads by reading All About Monads, version 1.0.2.
I though of defining a
W licie z czw, 02-10-2003, godz. 11:13, Juanma Barranquero pisze:
The intent is that Counted objects count the number of times an
operation is applied to them.
As you discovered, there is no meaningful count of operations. If an
operation doesn't do anything, do you count it? I suppose yes -
On Thu, 02 Oct 2003 11:22:13 +0200
Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] wrote:
As you discovered, there is no meaningful count of operations. If an
operation doesn't do anything, do you count it?
It's not about counting the operations (that's just an example), but
accumulating any kind
I'm not trying to create useful monads (I'm pretty sure they
aren't :),
but understanding the concepts. So, the question remains:
when the monad
laws say that
(return x) = f == f x
The Monad class is just called Monad because it is intended
to cover a monad. But it doesn't ensure the
So, the question remains: when the monad
laws say that
(return x) = f == f x
what is intended in that ==?
Observational equivalence.
For monads like list and maybe, this boils down to the normal equality because
the standard equality on these types is exactly observational equality.
On Thu, 02 Oct 2003 12:59:25 +0200
Juanma Barranquero [EMAIL PROTECTED] wrote:
On Thu, 02 Oct 2003 11:22:13 +0200
Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] wrote:
As you discovered, there is no meaningful count of operations. If an
operation doesn't do anything, do you count it?
The
On Thu, 2 Oct 2003 13:16:13 +0200
[EMAIL PROTECTED] wrote:
The Monad class is just called Monad because it is intended
to cover a monad. But it doesn't ensure the laws. That is your
sole responsibility.
Yeah, I know. But it's difficult to ensure I'm satisfying the laws when
I'm not entirely
W licie z czw, 02-10-2003, godz. 12:59, Juanma Barranquero pisze:
It's not about counting the operations (that's just an example), but
accumulating any kind of state. For example:
data Accum a = Ac [a] a
instance Monad Accum where
return x = Ac [x] x
Ac _ x = f = let
On Thu, 2 Oct 2003 12:30:54 +0100
Alastair Reid [EMAIL PROTECTED] wrote:
Observational equivalence.
For monads like list and maybe, this boils down to the normal equality because
the standard equality on these types is exactly observational equality.
For monads like IO, you can't define
W licie z czw, 02-10-2003, godz. 14:25, Juanma Barranquero pisze:
Yeah, I know. But it's difficult to ensure I'm satisfying the laws when
I'm not entirely sure what do they ask from me...
1. (return x) = f == f x
2. m = return == m
3. (m = f) = g == m = (\x - f x = g)
My intuition:
1 2.
On Thu, 02 Oct 2003 14:27:29 +0200
Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] wrote:
Accumulating state is fine. These definitions don't accumulate state:
'return' should yield a neutral state, and the above = ignores the
state of the lhs.
You're right.
data Accum s a = Ac [s] a
Incidentally, it is quite common to define a Monad instance but no Eq
instance. (e.g., the IO monad, most parser monads, most state transformer
monads, etc.)
So you should not interpret the '==' in the monad law as requiring you to
define an Eq instance.
If you do define an Eq instance, it
From your examples and interpretations, it looks like you need to become
more familiar and comfortable with -using- monads before you bother
trying to write one. Then once you have that down, seeing how -correct-
monads work would probably be the next most helpful thing. You'll have
a very hard
On Thu, 2 Oct 2003 16:09:11 +0100, Alastair Reid [EMAIL PROTECTED] wrote:
So you should not interpret the '==' in the monad law as requiring you to
define an Eq instance.
If you do define an Eq instance, it ought to be reflexive, symmetric and
transitive (i.e., an equivalence) if you want
15 matches
Mail list logo