
Hello, I would an examples of monads that are pure, i.e. no side-effects. Thank you, Vasili

You have fallen into the misconception that monads are impure, they are not.
Many monad tutorials begin (erroneously) with the lines "monads allow
you to do impure programming in Haskell."
This is false, monads are pure, it's IO that's impure, not the monadic
programming style. Monads let you *emulate* an impure style in pure
code, but it's nothing more than this: an emulation.
So in summary you can take any monad you want, and it will be pure,
however it's underlying implementation may not be (such is the case
with IO, for example). Consider any of:
-- State,
-- List,
-- Cont,
-- ... literally any monad, some may be more "obviously pure" than
others, but hey, people say that about me all the time.
kris
On Sat, Sep 29, 2012 at 9:57 PM, Vasili I. Galchin
Hello,
I would an examples of monads that are pure, i.e. no side-effects.
Thank you,
Vasili
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

From:
http://www.haskell.org/haskellwiki/Monad
"The computation doesn't have to be impure and can be pure itself as
well. Then monads serve to provide the benefits of separation of
concerns, and automatic creation of a computational "pipeline"."
On Sat, Sep 29, 2012 at 6:57 PM, Vasili I. Galchin
Hello,
I would an examples of monads that are pure, i.e. no side-effects.
Thank you,
Vasili
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- -- Regards, KC

Vasili I. Galchin wrote:
I would an examples of monads that are pure, i.e. no side-effects.
One view of programming in monadic style is: You call return and >>= all the time. (Either you call it directly, or do notation calls it for you). So if you want to understand whether a monad "has side-effects", you should look at the implementation of return and >>=. If the implementation of return and >>= is written in pure Haskell (without unsafePerformIO or calling C code etc.), the monad is pure. Tillmann

On 9/30/12 7:00 AM, Tillmann Rendel wrote:
Vasili I. Galchin wrote:
I would an examples of monads that are pure, i.e. no side-effects.
One view of programming in monadic style is: You call return and >>= all the time. (Either you call it directly, or do notation calls it for you). So if you want to understand whether a monad "has side-effects", you should look at the implementation of return and >>=. If the implementation of return and >>= is written in pure Haskell (without unsafePerformIO or calling C code etc.), the monad is pure.
I'm not sure return and bind will give you the information you seek, however. In order to obey the monad laws, return and bind must be (for all intents and purposes) pure. The place to look for "impurities" is the primitive operations of the monad; i.e., those which cannot be implemented using return and bind. These are the operations which take you out of a free monad and the operations which must be given some special semantic interpretation. -- Live well, ~wren

On 12-09-29 09:57 PM, Vasili I. Galchin wrote:
I would an examples of monads that are pure, i.e. no side-effects.
What does "side effect" mean, to you? Definition? Because some people say "State has no side effect", and some other people say "State has side effects". The two groups use different definitions.

On Sep 30, 2012 10:56 AM, "Albert Y. C. Lai"
On 12-09-29 09:57 PM, Vasili I. Galchin wrote:
I would an examples of monads that are pure, i.e. no
side-effects.
What does "side effect" mean, to you? Definition?
When discussing monads, at least, a side effect is an effect that is triggered by merely evaluating an expression. A monad is an interface that decouples effects from evaluation.
Because some people say "State has no side effect", and some other people
say "State has side effects". The two groups use different definitions.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Sep 30, 2012 at 6:33 PM, Jake McArthur
On Sep 30, 2012 10:56 AM, "Albert Y. C. Lai"
wrote: On 12-09-29 09:57 PM, Vasili I. Galchin wrote:
I would an examples of monads that are pure, i.e. no side-effects.
What does "side effect" mean, to you? Definition?
When discussing monads, at least, a side effect is an effect that is triggered by merely evaluating an expression. A monad is an interface that decouples effects from evaluation.
Ohh, I like that quote.., that's another good one.. kris

On 12-09-30 06:33 PM, Jake McArthur wrote:
When discussing monads, at least, a side effect is an effect that is triggered by merely evaluating an expression. A monad is an interface that decouples effects from evaluation.
I don't understand that definition. Or maybe I do subconsciously. I have s :: State Int () s = do { x <- get; put (x+1) } Is there an effect triggered by merely evaluating s? I have m :: IO () m = if True then putStrLn "x" else putChar 'y' Is there an effect triggered by merely evaluating m? What counts as "evaluate"?

"Albert Y. C. Lai"
On 12-09-30 06:33 PM, Jake McArthur wrote:
When discussing monads, at least, a side effect is an effect that is triggered by merely evaluating an expression. A monad is an interface that decouples effects from evaluation.
I don't understand that definition. Or maybe I do subconsciously.
I have
s :: State Int () s = do { x <- get; put (x+1) }
Is there an effect triggered by merely evaluating s?
I have
m :: IO () m = if True then putStrLn "x" else putChar 'y'
Is there an effect triggered by merely evaluating m?
What counts as "evaluate"?
Evaluation! Consider m `seq` 42. m is evaluated, but to no effect. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk

On 12-10-01 05:34 AM, Jon Fairbairn wrote:
"Albert Y. C. Lai"
writes: On 12-09-30 06:33 PM, Jake McArthur wrote:
When discussing monads, at least, a side effect is an effect that is triggered by merely evaluating an expression. A monad is an interface that decouples effects from evaluation.
I don't understand that definition. Or maybe I do subconsciously.
I have
s :: State Int () s = do { x <- get; put (x+1) }
Is there an effect triggered by merely evaluating s?
I have
m :: IO () m = if True then putStrLn "x" else putChar 'y'
Is there an effect triggered by merely evaluating m?
What counts as "evaluate"?
Evaluation! Consider m `seq` 42. m is evaluated, but to no effect.
Sure thing. So s has no side effect, and m has no side effect. Since they have no side effect, there is no effect to be decoupled from evaluation.
participants (8)
-
Albert Y. C. Lai
-
Jake McArthur
-
Jon Fairbairn
-
KC
-
Kristopher Micinski
-
Tillmann Rendel
-
Vasili I. Galchin
-
wren ng thornton