Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  IO and purity (Kim-Ee Yeoh)
   2. Re:  IO and purity (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   3. Re:  IO and purity (Joel Neely)
   4. Re:  IO and purity (Alexey Shmalko)


----------------------------------------------------------------------

Message: 1
Date: Sun, 26 Apr 2015 19:04:05 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] IO and purity
Message-ID:
        <capy+zdsgwowi8aruwnwcnvtqz00ayw0_mxhojpemvdpk+9_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Apr 26, 2015 at 5:16 PM, Jakob Holderbaum <[email protected]> wrote:

> I am myself an absolute beginner in Haskell and Functional Thinking so I
> hope to get some constructive feedback on my mental image of this situation.


When you write: "From the perspective of the programm, you just call a
function without argument that returns a string"

you veer close to the lousy thinking that Everything is a Function. Conal
Elliott did the delousing here:

http://conal.net/blog/posts/everything-is-a-function-in-haskell

Have a read, and if you're not convinced, come back here and ask for more
help.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150426/822b5090/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 26 Apr 2015 17:50:59 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] IO and purity
Message-ID:
        <CAJbEW8ODyPdBcS6uomKhLEzm1b_=_ynt5hn4gfc9rktnchf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks for removing a misconception about everything being a function.

My original example used writeFile, which is why I used the term 'function'.

Refactoring text is more difficult as compared to haskell code :)

On 26 April 2015 at 17:34, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Sun, Apr 26, 2015 at 5:16 PM, Jakob Holderbaum <[email protected]>
> wrote:
>
>> I am myself an absolute beginner in Haskell and Functional Thinking so I
>> hope to get some constructive feedback on my mental image of this situation.
>
>
> When you write: "From the perspective of the programm, you just call a
> function without argument that returns a string"
>
> you veer close to the lousy thinking that Everything is a Function. Conal
> Elliott did the delousing here:
>
> http://conal.net/blog/posts/everything-is-a-function-in-haskell
>
> Have a read, and if you're not convinced, come back here and ask for more
> help.
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150426/61d877e6/attachment-0001.html>

------------------------------

Message: 3
Date: Sun, 26 Apr 2015 07:22:29 -0500
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] IO and purity
Message-ID:
        <caeezxaihdv+mr7d60efe+ppi96rmaxuqxto74mrgztjmj8g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Shishir,

I'll reply as an humble programmer, not a category theorist. For me the
clarifying example was to contrast

putStrLn (getLine ++ getLine)


with

s = square 3 + square 4


where

square x = x * x


There is absolutely nothing that "leaks" between the two sub-expressions
involving square, so I'm free to rewrite as:

a = square 3
b = square 4
s = a + b


or

b = square 4
a = square 3
s = a + b


or

x = square 7
b = square 4
a = square 3
s = a + b
y = square 8


or

hh m n = square m + square n
x = square 7
s = hh 3 4
y = square 8


without altering the value of s or any surrounding computation. In that
last case, I can now freely intermingle uses of hh and square without risk.

But if I were to attempt the same gymnastics with putStrLn and getLine, I
wouldn't have those freedoms. The order of evaluation/performance now
becomes critical.

So the monad provides a way to manage the composition, and the type system
ensures visibility to the fact that something more is going on when a
defined function includes IO behavior.

Hope that helps,
-jn-






On Sun, Apr 26, 2015 at 4:59 AM, Shishir Srivastava <
[email protected]> wrote:

> Hi,
>
> Can someone please explain how IO operations do not fit in the pure
> category of mathematical function in that they have to be implemented via
> Monads.
>
> For e.g. the getLine function has the type IOString and it reads the
> input from the user. Now as I see it the output of getLine will always be
> same if the input remain same (i.e. for input "X" getLine will always
> return "X" ) which is the constraint on mathematical functions.
>
> Therefore I don't see why monads are necessary for implementing IO in pure
> languages.
>
> I can understand why Date and Random functions have be implemented via
> monads because their output will always change.
>
> Thanks,
> Shishir
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150426/7cec9393/attachment-0001.html>

------------------------------

Message: 4
Date: Sun, 26 Apr 2015 12:44:25 +0000
From: Alexey Shmalko <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] IO and purity
Message-ID:
        <CAFC2PC7MbOGWTjCpsFi86pBWHw=hc2+rbsotyh1+0cq7++i...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You can't do

putStrLn (getLine ++ getLine)

so of course you can't do such transformations. I would suggest you rewrite
your IO action without any syntactic sugar (with plain >> and >>=) first
and then try to do transformations.

I general, I find it useful to think of IO actions in two ways:
- as a value of IO type that your main is (kind of instructions that
Haskell runtime should perform).
- the effects execution of this value causes.

You can think that the sole purpose of your program is to construct this IO
value, while its execution is performed kind of outside of your program. If
you think that way, IO is again pure, obeys all monad rules and
categorically valid monad.

Regards,
Alexey Shmalko

On Sun, Apr 26, 2015 at 3:22 PM Joel Neely <[email protected]> wrote:

> Shishir,
>
> I'll reply as an humble programmer, not a category theorist. For me the
> clarifying example was to contrast
>
> putStrLn (getLine ++ getLine)
>
>
> with
>
> s = square 3 + square 4
>
>
> where
>
> square x = x * x
>
>
> There is absolutely nothing that "leaks" between the two sub-expressions
> involving square, so I'm free to rewrite as:
>
> a = square 3
> b = square 4
> s = a + b
>
>
> or
>
> b = square 4
> a = square 3
> s = a + b
>
>
> or
>
> x = square 7
> b = square 4
> a = square 3
> s = a + b
> y = square 8
>
>
> or
>
> hh m n = square m + square n
> x = square 7
> s = hh 3 4
> y = square 8
>
>
> without altering the value of s or any surrounding computation. In that
> last case, I can now freely intermingle uses of hh and square without
> risk.
>
> But if I were to attempt the same gymnastics with putStrLn and getLine, I
> wouldn't have those freedoms. The order of evaluation/performance now
> becomes critical.
>
> So the monad provides a way to manage the composition, and the type system
> ensures visibility to the fact that something more is going on when a
> defined function includes IO behavior.
>
> Hope that helps,
> -jn-
>
>
>
>
>
>
> On Sun, Apr 26, 2015 at 4:59 AM, Shishir Srivastava <
> [email protected]> wrote:
>
>> Hi,
>>
>> Can someone please explain how IO operations do not fit in the pure
>> category of mathematical function in that they have to be implemented via
>> Monads.
>>
>> For e.g. the getLine function has the type IOString and it reads the
>> input from the user. Now as I see it the output of getLine will always be
>> same if the input remain same (i.e. for input "X" getLine will always
>> return "X" ) which is the constraint on mathematical functions.
>>
>> Therefore I don't see why monads are necessary for implementing IO in
>> pure languages.
>>
>> I can understand why Date and Random functions have be implemented via
>> monads because their output will always change.
>>
>> Thanks,
>> Shishir
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
>
> --
> Beauty of style and harmony and grace and good rhythm depend on
> simplicity. - Plato
>  _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150426/99e7a814/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 82, Issue 38
*****************************************

Reply via email to