Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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:  monads / do syntax (Thiago Negri)
   2. Re:  Error Loading Stdm.lhs in Haskell platform   2012
      (Stephen Tetley)
   3.  Thread Blocking (mukesh tiwari)
   4. Re:  Thread Blocking (Eugene Perederey)
   5. Re:  Thread Blocking (mukesh tiwari)
   6. Re:  Thread Blocking (Eugene Perederey)


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

Message: 1
Date: Tue, 4 Sep 2012 13:38:42 -0300
From: Thiago Negri <[email protected]>
Subject: Re: [Haskell-beginners] monads / do syntax
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <CABLneZvsjXsVTinNrhJG9hUkW_01d3-O=jeuqpjashs-ccp...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Go line by line, except the last one:
a) When you see the pattern "a <- b", just swap it with "b >>= \s ->";
b) When you see the pattern "b", put a ">>" at the end of the line.

In your case:

| h = (return 1 :: IO Integer) >>= \a ->
|    return 2 >>= \b ->
|    return (a + b + 1)


An example when you have a line without an assignment ("<-"), this:

| h = do a <- (return 1 :: IO Integer)
|        b <- (return 2)
|        putStrLn "Hello, world!"
|        return (a + b + 1)

Turns into:

| h = (return 1 :: IO Integer) >>= \a ->
|    return 2 >>= \b ->
|    putStrLn "Hello, world!" >>
|    return (a + b + 1)


2012/9/4 Christopher Howard <[email protected]>:
> What does the following do expression translate into? (I.e., using >>=
> operator and lambda functions.)
>
> code:
> --------
> h = do a <- (return 1 :: IO Integer)
>        b <- (return 2)
>        return (a + b + 1)
> --------



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

Message: 2
Date: Tue, 4 Sep 2012 17:40:45 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Error Loading Stdm.lhs in Haskell
        platform        2012
To: Iwan Awaludin <[email protected]>
Cc: [email protected]
Message-ID:
        <CAB2TPRDoOVD_M4Br-=vfgdggakw0p3xukh1qtyrtt4h2pmc...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

The code for the book is written in Haskell '98, but recent versions
of GHC default to Haskell2010.

A salient difference between H98 and H2012 is the removed of n + k
patterns which generates the error you are seeing.

I can't find the exact command to use in the GHC docs to enable H98,
but you could try the following old flag which disables GHCs
extensions:

> ghci  -fno-glasgow-exts



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

Message: 3
Date: Wed, 5 Sep 2012 00:24:30 +0530
From: mukesh tiwari <[email protected]>
Subject: [Haskell-beginners] Thread Blocking
To: [email protected]
Message-ID:
        <CAFHZvE9pKn7_EM9t=x3sfay3oqvnmrmk_7xe9ro9jswbqpn...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello All
I was going trough Real World Haskell and it says "If we try to put a value
into an MVar that is already full, our thread is put to sleep until another
thread takes the value out". I wrote a simple code to block main

import Data.List
import Control.Concurrent

fun m = do
   putMVar m 10
   return ()


main = do
  m <- newEmptyMVar
  forkIO $ fun m
  putMVar m 10
  return ()

What I am expecting that main should be blocked at least couple of times
but its behaving more deterministically.
[mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
Concurrent.hs
[1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
Linking Concurrent ...
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$

I am expecting to get thread blocked indefinitely on MVar at least half the
time. Could some one please tell me why this deterministic behavior ?
Regards
Mukesh Tiwari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120905/3a051faf/attachment-0001.htm>

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

Message: 4
Date: Tue, 4 Sep 2012 12:02:51 -0700
From: Eugene Perederey <[email protected]>
Subject: Re: [Haskell-beginners] Thread Blocking
To: mukesh tiwari <[email protected]>
Cc: [email protected]
Message-ID:
        <CAFTqo17X50xRZntCuG=7Z7LpEm=t8-xxlgfugbn+gmidrxv...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Why do you think main should block more than once?
I see only two possible scenarios: the fun thread puts to mvar first
thus blocking main,
or 10 is put into mvar in main, blocking the other thread indefinitely.


On 4 September 2012 11:54, mukesh tiwari <[email protected]> wrote:
> Hello All
> I was going trough Real World Haskell and it says "If we try to put a value
> into an MVar that is already full, our thread is put to sleep until another
> thread takes the value out". I wrote a simple code to block main
>
> import Data.List
> import Control.Concurrent
>
> fun m = do
>    putMVar m 10
>    return ()
>
>
> main = do
>   m <- newEmptyMVar
>   forkIO $ fun m
>   putMVar m 10
>   return ()
>
> What I am expecting that main should be blocked at least couple of times
> but its behaving more deterministically.
> [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
> Concurrent.hs
> [1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
> Linking Concurrent ...
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> [mukesh.tiwari@ Programming]$
>
> I am expecting to get thread blocked indefinitely on MVar at least half the
> time. Could some one please tell me why this deterministic behavior ?
> Regards
> Mukesh Tiwari
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Best,
Eugene Perederey



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

Message: 5
Date: Wed, 5 Sep 2012 00:46:36 +0530
From: mukesh tiwari <[email protected]>
Subject: Re: [Haskell-beginners] Thread Blocking
To: Eugene Perederey <[email protected]>
Cc: [email protected]
Message-ID:
        <CAFHZvE-=bJVtdE9aRryYkkVg7V6u-GVj1G71h5q-o=cohvw...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Eugene
Thank you for reply.

On Wed, Sep 5, 2012 at 12:32 AM, Eugene Perederey <
[email protected]> wrote:

> Why do you think main should block more than once?
> I see only two possible scenarios: the fun thread puts to mvar first
> thus blocking main,
>

So at least in this case I should get thread blocked indefinitely in an
MVar operation


> or 10 is put into mvar in main, blocking the other thread indefinitely.
>

or main will execute and fun thread will die. There are 50 - 50 chance for
this ( assuming both are equally likely ). I did some modification in my
code and Now I am  consistently getting "Concurrent: thread blocked
indefinitely in an MVar operation"

import Data.List
import Control.Concurrent

fun m = do
   putMVar m 10
   return ()


main = do
  m <- newEmptyMVar
  forkIO $ fun m
  putStrLn "I am inside main"
  putMVar m 10
  return ()

[mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
Concurrent.hs
[1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
Linking Concurrent ...
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
I am inside main
Concurrent: thread blocked indefinitely in an MVar operation
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
I am inside main
Concurrent: thread blocked indefinitely in an MVar operation
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
I am inside main
Concurrent: thread blocked indefinitely in an MVar operation
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
I am inside main
Concurrent: thread blocked indefinitely in an MVar operation
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
I am inside main
Concurrent: thread blocked indefinitely in an MVar operation

My question is why the outcome in first case is deterministic. Every time
the code executing  ( at least half the time main thread should be blocked
) .

Regards
Mukesh Tiwari


>
> On 4 September 2012 11:54, mukesh tiwari <[email protected]>
> wrote:
> > Hello All
> > I was going trough Real World Haskell and it says "If we try to put a
> value
> > into an MVar that is already full, our thread is put to sleep until
> another
> > thread takes the value out". I wrote a simple code to block main
> >
> > import Data.List
> > import Control.Concurrent
> >
> > fun m = do
> >    putMVar m 10
> >    return ()
> >
> >
> > main = do
> >   m <- newEmptyMVar
> >   forkIO $ fun m
> >   putMVar m 10
> >   return ()
> >
> > What I am expecting that main should be blocked at least couple of times
> > but its behaving more deterministically.
> > [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
> > Concurrent.hs
> > [1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
> > Linking Concurrent ...
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> > [mukesh.tiwari@ Programming]$
> >
> > I am expecting to get thread blocked indefinitely on MVar at least half
> the
> > time. Could some one please tell me why this deterministic behavior ?
> > Regards
> > Mukesh Tiwari
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
> --
> Best,
> Eugene Perederey
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120905/2ab52dc8/attachment-0001.htm>

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

Message: 6
Date: Tue, 4 Sep 2012 12:27:29 -0700
From: Eugene Perederey <[email protected]>
Subject: Re: [Haskell-beginners] Thread Blocking
To: mukesh tiwari <[email protected]>
Cc: [email protected]
Message-ID:
        <caftqo16tp92gs9pnkadptsscj9qerb1xnhkh4_ctgowtybu...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I added a few prints to your code

fun m = do
  putStrLn "fun1"
  putMVar m 10
  putStrLn "fun2"


main = do
  m <- newEmptyMVar
  forkIO $ fun m
  putStrLn "main1"
  putMVar m 10
  putStrLn "main2"

It works 50/50 for me in Mac OS X 10.6.8.

On 4 September 2012 12:16, mukesh tiwari <[email protected]> wrote:
> Hi Eugene
> Thank you for reply.
>
> On Wed, Sep 5, 2012 at 12:32 AM, Eugene Perederey
> <[email protected]> wrote:
>>
>> Why do you think main should block more than once?
>> I see only two possible scenarios: the fun thread puts to mvar first
>> thus blocking main,
>
>
> So at least in this case I should get thread blocked indefinitely in an MVar
> operation
>
>>
>> or 10 is put into mvar in main, blocking the other thread indefinitely.
>
>
> or main will execute and fun thread will die. There are 50 - 50 chance for
> this ( assuming both are equally likely ). I did some modification in my
> code and Now I am  consistently getting "Concurrent: thread blocked
> indefinitely in an MVar operation"
>
>
> import Data.List
> import Control.Concurrent
>
> fun m = do
>    putMVar m 10
>    return ()
>
>
> main = do
>   m <- newEmptyMVar
>   forkIO $ fun m
>   putStrLn "I am inside main"
>
>   putMVar m 10
>   return ()
>
> [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
> Concurrent.hs
> [1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
> Linking Concurrent ...
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> I am inside main
> Concurrent: thread blocked indefinitely in an MVar operation
>
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> I am inside main
> Concurrent: thread blocked indefinitely in an MVar operation
>
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> I am inside main
> Concurrent: thread blocked indefinitely in an MVar operation
>
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> I am inside main
> Concurrent: thread blocked indefinitely in an MVar operation
>
> [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
> I am inside main
> Concurrent: thread blocked indefinitely in an MVar operation
>
> My question is why the outcome in first case is deterministic. Every time
> the code executing  ( at least half the time main thread should be blocked )
> .
>
> Regards
> Mukesh Tiwari
>
>>
>>
>> On 4 September 2012 11:54, mukesh tiwari <[email protected]>
>> wrote:
>> > Hello All
>> > I was going trough Real World Haskell and it says "If we try to put a
>> > value
>> > into an MVar that is already full, our thread is put to sleep until
>> > another
>> > thread takes the value out". I wrote a simple code to block main
>> >
>> > import Data.List
>> > import Control.Concurrent
>> >
>> > fun m = do
>> >    putMVar m 10
>> >    return ()
>> >
>> >
>> > main = do
>> >   m <- newEmptyMVar
>> >   forkIO $ fun m
>> >   putMVar m 10
>> >   return ()
>> >
>> > What I am expecting that main should be blocked at least couple of times
>> > but its behaving more deterministically.
>> > [mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
>> > Concurrent.hs
>> > [1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
>> > Linking Concurrent ...
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
>> > [mukesh.tiwari@ Programming]$
>> >
>> > I am expecting to get thread blocked indefinitely on MVar at least half
>> > the
>> > time. Could some one please tell me why this deterministic behavior ?
>> > Regards
>> > Mukesh Tiwari
>> >
>> >
>> > _______________________________________________
>> > Beginners mailing list
>> > [email protected]
>> > http://www.haskell.org/mailman/listinfo/beginners
>> >
>>
>>
>>
>> --
>> Best,
>> Eugene Perederey
>
>



-- 
Best,
Eugene Perederey



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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 51, Issue 7
****************************************

Reply via email to