[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Achim Schneider
Henning Thielemann schlepp...@henning-thielemann.de wrote:

 If it is generally possible to use unsafeInterleaveIO such that it
 executes actions in the right order, wouldn't this allow the
 definition of a general lazy IO monad?

The question is what right order means.

Let B1..Bn be some arbitrary IO-Actions.
Let A1..An be some arbitrary IO Actions passed to unsafeInterleaveIO

You're guaranteed that
a) Bk+1 is executed after Bk
b) Ak+1 is executed after Ak

, all by virtue of the IO Monad.

However, usage of unsafeInterleaveIO means that you aren't guaranteed
that A1..An happens _exactly_ between any pair of Bk and Bk+1: The
total ordering of actions is circumvented. Semantically, this is
equivalent to sparking a thread on a uniprocessor, and equivalent to
sparking a thread on a multiprocessor for all but the rarest
combinations of IO actions.


There are no lazy monads. Monads imply explicit sequencing... writing

kiss girl == speakTo girl

, denoting either (fist kiss the girl, then pass the result of that to
speakTo girl) or (first speak to the girl, then pass the result of that
to kiss girl) would, OTOH, certainly makes sense and certainly
(well, depending on girl and setting) is undeterministic in both
execution order and result.

The question thus becomes:
Does arbitrary ordering of actions result in the same (in the id sense)
result, and do I care more about the aggregate result than its
ordering, or do I only care about ordering of actions for a certain
definition of 'same result'?

Implementation of such a beast is left to the semantically
inclined reader ;)

In the meantime, I'm happy to just carelessly use unsafe*IO.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Henning Thielemann


On Fri, 2 Jan 2009, Achim Schneider wrote:


Henning Thielemann schlepp...@henning-thielemann.de wrote:


If it is generally possible to use unsafeInterleaveIO such that it
executes actions in the right order, wouldn't this allow the
definition of a general lazy IO monad?


The question is what right order means.

Let B1..Bn be some arbitrary IO-Actions.
Let A1..An be some arbitrary IO Actions passed to unsafeInterleaveIO

You're guaranteed that
a) Bk+1 is executed after Bk
b) Ak+1 is executed after Ak

, all by virtue of the IO Monad.


If all Ak's are defered using individual unsafeInterleaveIO's then it is 
not guaranteed that A[k+1] is executed after A[k]. That's my problem.


Check:
Prelude fmap snd $ Monad.liftM2 (,) (unsafeInterleaveIO getLine) 
(unsafeInterleaveIO getLine)

If unsafely interleaved actions would be executed in order, then this 
would first ask you for the first pair member, then for the second one, 
then echo the second one. Actually it asks only for the second one and 
prints it.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread David Menendez
On Thu, Jan 1, 2009 at 7:39 PM, Achim Schneider bars...@web.de wrote:

 There are no lazy monads. Monads imply explicit sequencing...

Huh? How are you defining lazy monad?

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread roconnor

On Fri, 2 Jan 2009, Achim Schneider wrote:


There are no lazy monads. Monads imply explicit sequencing... writing


I think this is an extremely bad thing to say and is a source of 
misunderstanding about monads and evaluation.  Most monads _are_ lazy, and 
it is important to understand that when trying to understand the run-time 
properties of your monadic code.


Monads sequence effects, but evaluation is an almost orthogonal issue. 
Here is a recent thread where I talk about laziness:


http://www.reddit.com/r/haskell/comments/7itbi/mapm_mapm_and_monadic_statements/c06s6pm

(for the short short story, simply try out

take 10 $ execWriter (sequence_ (repeat (tell x)))

)

Furthermore, the code in my article on recursive do from The.Monad.Reader 
issue #6 http://www.haskell.org/sitewiki/images/1/14/TMR-Issue6.pdf 
requires the monads to be lazy in order to tie the knot.


--
Russell O'Connor  http://r6.ca/
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Achim Schneider
Henning Thielemann lemm...@henning-thielemann.de wrote:

 
 On Fri, 2 Jan 2009, Achim Schneider wrote:
 
  Henning Thielemann schlepp...@henning-thielemann.de wrote:
 
  If it is generally possible to use unsafeInterleaveIO such that it
  executes actions in the right order, wouldn't this allow the
  definition of a general lazy IO monad?
 
  The question is what right order means.
 
  Let B1..Bn be some arbitrary IO-Actions.
  Let A1..An be some arbitrary IO Actions passed to unsafeInterleaveIO
 
  You're guaranteed that
  a) Bk+1 is executed after Bk
  b) Ak+1 is executed after Ak
 
  , all by virtue of the IO Monad.
 
 If all Ak's are defered using individual unsafeInterleaveIO's then it
 is not guaranteed that A[k+1] is executed after A[k]. That's my
 problem.
 
 Check:
 Prelude fmap snd $ Monad.liftM2 (,) (unsafeInterleaveIO getLine)
 Prelude (unsafeInterleaveIO getLine)
 
 If unsafely interleaved actions would be executed in order, then this 
 would first ask you for the first pair member, then for the second
 one, then echo the second one. Actually it asks only for the second
 one and prints it.

module Main where
import System.IO.Unsafe

chooseAct :: String - IO (IO ())
chooseAct s = do
putStrLn $ s ++ ?
l - getLine
if (l == s)
then return $ putStrLn $ w00t! a  ++ s
else return $ putStrLn bah

getActs :: IO [IO ()]
getActs = mapM chooseAct [foo, bar, baz]

main0 = unsafeInterleaveIO getActs = unsafeInterleaveIO . sequence_
main1 = unsafeInterleaveIO getActs = sequence_

main = main0  main1

There you've got the ordering.

It's quite easy to write a haskell program that reduces itself to 
main = return (), though.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Brandon S. Allbery KF8NH

On 2009 Jan 1, at 20:08, David Menendez wrote:
On Thu, Jan 1, 2009 at 7:39 PM, Achim Schneider bars...@web.de  
wrote:

There are no lazy monads. Monads imply explicit sequencing...


Huh? How are you defining lazy monad?



We've had this discussion before; somewhere in the archives is an  
example of a State monad doing things in data-driven order instead of  
the apparently explicit monadic sequencing.  Monads don't insure  
sequencing unless designed to do so (as, for example, IO).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Achim Schneider
Achim Schneider bars...@web.de wrote:

 [...]
actually, even better:

main = do
acts - unsafeInterleaveIO getActs
putStrLn dumdidum
sequence_ acts

, which, at least on my machine, prints dumdidum before asking for foo.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Achim Schneider
Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote:

 On 2009 Jan 1, at 20:08, David Menendez wrote:
  On Thu, Jan 1, 2009 at 7:39 PM, Achim Schneider bars...@web.de  
  wrote:
  There are no lazy monads. Monads imply explicit sequencing...
 
  Huh? How are you defining lazy monad?
 
 
 We've had this discussion before; somewhere in the archives is an  
 example of a State monad doing things in data-driven order instead
 of the apparently explicit monadic sequencing.  Monads don't
 insure sequencing unless designed to do so (as, for example, IO).
 
The more I try to put stuff into words, the more I part from lambda
calculus into the regions of syntactical pitfalls. Therefore, I'm just
going to shut up.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread David Menendez
On Thu, Jan 1, 2009 at 8:29 PM, Brandon S. Allbery KF8NH
allb...@ece.cmu.edu wrote:
 On 2009 Jan 1, at 20:08, David Menendez wrote:

 On Thu, Jan 1, 2009 at 7:39 PM, Achim Schneider bars...@web.de wrote:

 There are no lazy monads. Monads imply explicit sequencing...

 Huh? How are you defining lazy monad?


 We've had this discussion before; somewhere in the archives is an example of
 a State monad doing things in data-driven order instead of the apparently
 explicit monadic sequencing.  Monads don't insure sequencing unless
 designed to do so (as, for example, IO).

Certainly. I asked because Achim might have been making a point about
about call-by-need versus call-by-value, or something.

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: unsafeInterleaveIO respecting order of actions

2009-01-01 Thread Achim Schneider
David Menendez d...@zednenem.com wrote:

 On Thu, Jan 1, 2009 at 8:29 PM, Brandon S. Allbery KF8NH
 allb...@ece.cmu.edu wrote:
  On 2009 Jan 1, at 20:08, David Menendez wrote:
 
  On Thu, Jan 1, 2009 at 7:39 PM, Achim Schneider bars...@web.de
  wrote:
 
  There are no lazy monads. Monads imply explicit sequencing...
 
  Huh? How are you defining lazy monad?
 
 
  We've had this discussion before; somewhere in the archives is an
  example of a State monad doing things in data-driven order instead
  of the apparently explicit monadic sequencing.  Monads don't
  insure sequencing unless designed to do so (as, for example, IO).
 
 Certainly. I asked because Achim might have been making a point about
 about call-by-need versus call-by-value, or something.
 
Nah, I was speculating about (possibly better) ways to specify
dependencies of side-effects. Ways, that is, that enable the computer
to directly implement your perception of priorities like importance of
ordering vs. importance of results.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe