Using a monadic operation in a list comprehension.

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

Using a monadic operation in a list comprehension.

Derek McLoughlin
Hi,

I'm trying to get Graham Hutton's "Programming with Effects" article
(http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead
of the Tree he provides.

My code is here:

https://gist.github.com/derekmcloughlin/95ab690e0c07c5a7221e

The compiler is complaining about the use of

   lab <- mlabel c

in the list comprehension:

Couldn't match expected type ?[Tree (a, Int)]?
                with actual type ?ST (Tree (a, Int))?

This makes sense, but is there any way to execute the monad operation
"mlabel" within the list comprehension? I've tried the
MonadComprehensions extension but still get an error.

Derek.

Reply | Threaded
Open this post in threaded view
|

Using a monadic operation in a list comprehension.

Kim-Ee Yeoh
Administrator
On Sun, Sep 21, 2014 at 9:02 PM, Derek McLoughlin <
derek.mcloughlin at gmail.com> wrote:

> I'm trying to get Graham Hutton's "Programming with Effects" article
> (http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead
> of the Tree he provides.
>

Hi Derek,

This is a lovely problem that's inspired a bunch of interesting papers
recently.

Here's a stab at the compilation error you're facing:

http://www.atamo.com/blog/how-to-solve-a-tricky-monad-problem-1/

Enjoy  :)

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140922/5b88c000/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Using a monadic operation in a list comprehension.

Derek McLoughlin
Thanks very much for your clear explanation! Worked perfectly. You're
right about the ST - I got very confused at the start with
Control.Monad.ST. I'll be removing Graham's ST in favour of the
'normal' State monad.

On 21 September 2014 19:38, Kim-Ee Yeoh <ky3 at atamo.com> wrote:

>
> On Sun, Sep 21, 2014 at 9:02 PM, Derek McLoughlin
> <derek.mcloughlin at gmail.com> wrote:
>>
>> I'm trying to get Graham Hutton's "Programming with Effects" article
>> (http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead
>> of the Tree he provides.
>
>
> Hi Derek,
>
> This is a lovely problem that's inspired a bunch of interesting papers
> recently.
>
> Here's a stab at the compilation error you're facing:
>
> http://www.atamo.com/blog/how-to-solve-a-tricky-monad-problem-1/
>
> Enjoy  :)
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>

Reply | Threaded
Open this post in threaded view
|

Using a monadic operation in a list comprehension.

Kim-Ee Yeoh
Administrator
On Mon, Sep 22, 2014 at 3:55 AM, Derek McLoughlin <
derek.mcloughlin at gmail.com> wrote:

> Thanks very much for your clear explanation! Worked perfectly.


Thanks for taking the time to say this :)

I hope I didn't belabor the mismatched effects bit. Combining effects is a
wide open field of research if you look at papers like Extensible Effects,
Monad Coproducts, etc.

Point being, there just might be a way to make your code as originally
written compile and work as you expect it to. Ah, the joys of life at the
bleeding edge!

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140926/9f28f7c0/attachment.html>