Vasili I. Galchin | 30 Sep 03:57 2012
Picon

Monads

Hello,

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

Thank you,

Vasili

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Kristopher Micinski | 30 Sep 04:11 2012
Picon

Re: Monads

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 <vigalchin <at> gmail.com> wrote:
> Hello,
>
>         I would an examples of monads that are pure, i.e. no side-effects.
>
> Thank you,
>
> Vasili
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
KC | 30 Sep 04:13 2012
Picon

Re: Monads

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 <vigalchin <at> gmail.com> wrote:
> Hello,
>
>         I would an examples of monads that are pure, i.e. no side-effects.
>
> Thank you,
>
> Vasili
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

--

-- 
--
Regards,
KC
Tillmann Rendel | 30 Sep 13:00 2012
Picon

Re: Monads

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
wren ng thornton | 30 Sep 20:40 2012

Re: Monads

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
Albert Y. C. Lai | 30 Sep 16:54 2012
Picon

Re: Monads

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.
Jake McArthur | 1 Oct 00:33 2012
Picon

Re: Monads


On Sep 30, 2012 10:56 AM, "Albert Y. C. Lai" <trebla <at> vex.net> 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.

>
> 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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Kristopher Micinski | 1 Oct 00:37 2012
Picon

Re: Monads

On Sun, Sep 30, 2012 at 6:33 PM, Jake McArthur <jake.mcarthur <at> gmail.com> wrote:
>
> On Sep 30, 2012 10:56 AM, "Albert Y. C. Lai" <trebla <at> vex.net> 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
Albert Y. C. Lai | 1 Oct 06:12 2012
Picon

Re: Monads

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"?
Jon Fairbairn | 1 Oct 11:34 2012
X-Face
Picon
Picon

Re: Monads

"Albert Y. C. Lai" <trebla <at> vex.net> 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.

--

-- 
Jón Fairbairn                                 Jon.Fairbairn <at> cl.cam.ac.uk

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Albert Y. C. Lai | 2 Oct 03:17 2012
Picon

Re: Monads

On 12-10-01 05:34 AM, Jon Fairbairn wrote:
> "Albert Y. C. Lai" <trebla <at> vex.net> 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.

Gmane