Different semantics in "identical" do statement?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Different semantics in "identical" do statement?

staafmeister

In my program

do
  x <- do
    blah <- someFunc
    return blah
  return $ Constructor x

behaves differently from
do
  blah <- someFunc
  return $ Constructor blah

where the dots are identical. I would think that these programs should behave identically, by the monad laws.
The result of my program is that the second gives correct behaviour, while the first loops forever.

Greetings,
Gerben
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

Ross Mellgren
In what Monad?

-Ross

On Oct 9, 2009, at 5:43 PM, staafmeister wrote:

>
>
> In my program
>
> do
>  x <- do
>    blah <- someFunc
>    return blah
>  return $ Constructor x
>
> behaves differently from
> do
>  blah <- someFunc
>  return $ Constructor blah
>
> where the dots are identical. I would think that these programs should
> behave identically, by the monad laws.
> The result of my program is that the second gives correct behaviour,  
> while
> the first loops forever.
>
> Greetings,
> Gerben
> --
> View this message in context: http://www.nabble.com/Different-semantics-in-%22identical%22-do-statement--tp25828319p25828319.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com
> .
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

staafmeister

Ross Mellgren wrote
In what Monad?
Parsec Monad
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

Daniel Peebles
I vaguely remember on IRC someone pointing out that the Parsec monad
broke one of the laws. I think return _|_ >> x === _|_ which could be
causing your problem. I may be wrong though.

On Fri, Oct 9, 2009 at 5:59 PM, staafmeister <[hidden email]> wrote:

>
>
>
> Ross Mellgren wrote:
>>
>> In what Monad?
>>
>>
>
> Parsec Monad
>
> --
> View this message in context: http://www.nabble.com/Different-semantics-in-%22identical%22-do-statement--tp25828319p25828521.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

staafmeister

Daniel Peebles wrote
I vaguely remember on IRC someone pointing out that the Parsec monad
broke one of the laws. I think return _|_ >> x === _|_ which could be
causing your problem. I may be wrong though.
This could very well be it. I use lazy eval to construct a function that returns
its own argument (that is you supply the return value of the func as its arg).
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

staafmeister
In reply to this post by Daniel Peebles

Daniel Peebles wrote
I vaguely remember on IRC someone pointing out that the Parsec monad
broke one of the laws. I think return _|_ >> x === _|_ which could be
causing your problem. I may be wrong though.
Confirmed, working in the parsec monad

Prelude Text.Parsec> runP (do {x <- return undefined; return 10}) () "" ""
*** Exception: Prelude.undefined

In the IO Monad
Prelude Text.Parsec> do {x <- return undefined; return 10}
10

Should be fixed.
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

David Menendez-2
On Fri, Oct 9, 2009 at 6:47 PM, staafmeister <[hidden email]> wrote:

>
> Daniel Peebles wrote:
>>
>> I vaguely remember on IRC someone pointing out that the Parsec monad
>> broke one of the laws. I think return _|_ >> x === _|_ which could be
>> causing your problem. I may be wrong though.
>>
>>
>
> Confirmed, working in the parsec monad
>
> Prelude Text.Parsec> runP (do {x <- return undefined; return 10}) () "" ""
> *** Exception: Prelude.undefined
>
> In the IO Monad
> Prelude Text.Parsec> do {x <- return undefined; return 10}
> 10
>
> Should be fixed.

It looks like the problem is a strict field in the definition of
GenParser (specifically in Reply). From what I can tell, Parsec 3.0.1
should not have this problem.

--
Dave Menendez <[hidden email]>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Different semantics in "identical" do statement?

Alexander Dunlap
On Fri, Oct 9, 2009 at 4:25 PM, David Menendez <[hidden email]> wrote:

> On Fri, Oct 9, 2009 at 6:47 PM, staafmeister <[hidden email]> wrote:
>>
>> Daniel Peebles wrote:
>>>
>>> I vaguely remember on IRC someone pointing out that the Parsec monad
>>> broke one of the laws. I think return _|_ >> x === _|_ which could be
>>> causing your problem. I may be wrong though.
>>>
>>>
>>
>> Confirmed, working in the parsec monad
>>
>> Prelude Text.Parsec> runP (do {x <- return undefined; return 10}) () "" ""
>> *** Exception: Prelude.undefined
>>
>> In the IO Monad
>> Prelude Text.Parsec> do {x <- return undefined; return 10}
>> 10
>>
>> Should be fixed.
>
> It looks like the problem is a strict field in the definition of
> GenParser (specifically in Reply). From what I can tell, Parsec 3.0.1
> should not have this problem.
>
> --
> Dave Menendez <[hidden email]>
> <http://www.eyrie.org/~zednenem/>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

It works with Parsec 3.0.1 for me.

Alex
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe