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. Equivalent of IO Monad in other functional languages?
(Simon Kitching)
2. Re: Equivalent of IO Monad in other functional languages?
(Marcin Mrotek)
3. Re: Equivalent of IO Monad in other functional languages?
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
4. Re: Equivalent of IO Monad in other functional languages?
([email protected])
5. Re: Equivalent of IO Monad in other functional languages?
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
----------------------------------------------------------------------
Message: 1
Date: Sun, 15 Mar 2015 17:17:17 +0100
From: Simon Kitching <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Equivalent of IO Monad in other
functional languages?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
[Note: learning haskell, not familiar with other functional languages]
I have a question about handling impure operations in functional or
semi-functional languages other than Haskell (eg OCaml, F#, Scala, ..).
Haskell uses the IO monad to (a) cleanly separate pure and impure code,
and (b) prevent function-calls from being reordered when they have
side-effects that must happen in the right order. How do other languages
handle this?
AIUI, whether a Haskell function is 'pure' or not can be seen from its
method signature : if it returns IO then it is impure. All standard
library functions that have side-effects (read/write/etc) return IO, and
any function that uses an IO value must return type IO. Do other
functional languages (1) use a similar approach, or (2) not provide a
way to be certain that a function is 'pure' (side-effect-free)?
And AIUI the Haskell compiler/runtime can postpone evaluation of any
function (laziness), or reorder function calls whever it thinks this
good. However using the monad design pattern (deliberately) prevents
this (each operation passes its value as a parameter to the subsequent
operation, thus forcing an order of evaluation). Do other languages (a)
not support compiler/runtime reordering of functions, or (b) have some
other way of preventing functions with side-effects from being reordered?
Thanks..
Simon
------------------------------
Message: 2
Date: Sun, 15 Mar 2015 17:55:12 +0100
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Equivalent of IO Monad in other
functional languages?
Message-ID:
<cajcfpzmwuquh23a6tmxkf1w-xh20z5o3gvr19ms6pvg54mm...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hello,
F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/
(section 2, Types and Effects)
Best regards,
Marcin Mrotek
------------------------------
Message: 3
Date: Sun, 15 Mar 2015 22:45:03 +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] Equivalent of IO Monad in other
functional languages?
Message-ID:
<CAJbEW8O6d54hmO=4jinw4oja95k6mt2p5afscvchicx+dyn...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello Simon,
If you changed your perspective, you would realize that all functions in
haskell are pure.
A function is pure if it returns the same output if given the same input.
Every monadic function (including functions returning IO) is also pure.
For example,
putStrLn :: String -> IO ()
-- A function that takes a string, and returns an impure computation
-- which, when executed will print the given String.
For any string, putStrLn applied to that same string always describes the
same impure computation, thus the function is actually pure.
I am not familiar with any other functional language, but there are not
many purely functional ones out there [1].
I guess the impure ones get around this issue by giving in to impurity, but
I'm not sure.
I'll be interested in hearing more about the other languages too.
[1] :
http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
On 15 March 2015 at 22:25, Marcin Mrotek <[email protected]>
wrote:
> Hello,
>
> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/
> (section 2, Types and Effects)
>
> Best regards,
> Marcin Mrotek
> _______________________________________________
> 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/20150315/1b9bdcea/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 15 Mar 2015 13:49:04 -0400
From: [email protected]
To: "[email protected]"
<[email protected]>, The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics related to
Haskell <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Equivalent of IO Monad in other
functional languages?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
>From that perspective isn't every language pure? Haskell's still got
>"randomIO" and "print <=< readMVar"
Tom
El Mar 15, 2015, a las 13:15, "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]> escribi?:
> Hello Simon,
>
> If you changed your perspective, you would realize that all functions in
> haskell are pure.
> A function is pure if it returns the same output if given the same input.
> Every monadic function (including functions returning IO) is also pure.
> For example,
>
> putStrLn :: String -> IO ()
> -- A function that takes a string, and returns an impure computation
> -- which, when executed will print the given String.
>
> For any string, putStrLn applied to that same string always describes the
> same impure computation, thus the function is actually pure.
> I am not familiar with any other functional language, but there are not many
> purely functional ones out there [1].
> I guess the impure ones get around this issue by giving in to impurity, but
> I'm not sure.
>
> I'll be interested in hearing more about the other languages too.
>
> [1] : http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
>
> On 15 March 2015 at 22:25, Marcin Mrotek <[email protected]> wrote:
>> Hello,
>>
>> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/
>> (section 2, Types and Effects)
>>
>> Best regards,
>> Marcin Mrotek
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> --
> Regards
>
> Sumit Sahrawat
> _______________________________________________
> 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/20150315/2c3a178c/attachment-0001.html>
------------------------------
Message: 5
Date: Sun, 15 Mar 2015 23:27:58 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: [email protected]
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Equivalent of IO Monad in other
functional languages?
Message-ID:
<CAJbEW8N9bx1YogQJfaDc3o2yQ++ohN=qanjxan0nwdq25yg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Haskell is impure only when you use the unsafe* functions (atleast that's
how I understand purity).
My understanding is that a language is impure if it allows one to write
arbitrary IO within a function and still give it a proper (mathematical)
function type. In other words impurity arises only if you can unwrap the IO
monad (which is what the unsafe functions do).
The two examples you give above are pure under such a perspective, but I
might be wrong.
On 15 March 2015 at 23:19, <[email protected]> wrote:
> From that perspective isn't every language pure? Haskell's still got
> "randomIO" and "print <=< readMVar"
>
> Tom
>
>
> El Mar 15, 2015, a las 13:15, "Sumit Sahrawat, Maths & Computing, IIT
> (BHU)" <[email protected]> escribi?:
>
> Hello Simon,
>
> If you changed your perspective, you would realize that all functions in
> haskell are pure.
> A function is pure if it returns the same output if given the same input.
> Every monadic function (including functions returning IO) is also pure.
> For example,
>
> putStrLn :: String -> IO ()
> -- A function that takes a string, and returns an impure computation
> -- which, when executed will print the given String.
>
> For any string, putStrLn applied to that same string always describes the
> same impure computation, thus the function is actually pure.
> I am not familiar with any other functional language, but there are not
> many purely functional ones out there [1].
> I guess the impure ones get around this issue by giving in to impurity,
> but I'm not sure.
>
> I'll be interested in hearing more about the other languages too.
>
> [1] :
> http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure
>
> On 15 March 2015 at 22:25, Marcin Mrotek <[email protected]>
> wrote:
>
>> Hello,
>>
>> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/
>> (section 2, Types and Effects)
>>
>> Best regards,
>> Marcin Mrotek
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> --
> Regards
>
> Sumit Sahrawat
>
> _______________________________________________
> 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/20150315/1615f18f/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 43
*****************************************