Re: Do notation for arbitrary monads

From: Sebastian Fischer <sebf_at_informatik.uni-kiel.de>
Date: Wed, 07 Sep 2011 09:56:13 +0900

Hi Arthur,

yes, do-notation in PAKCS is only for IO. There is a type-class branch [1]
of the Muenster Curry Compiler (MCC) that supports do-notation for arbitrary
monads but MCC does not have the FlatCurry module and it is difficult to
port because MCC cannot parse Curry data from strings to read a FlatCurry
file.

I always used my own versions of >>= and return explicitly instead of
do-notation, when using custom monads in PAKCS.

Instead of using IORefs, you may want to look at PAKCS's Global module [2]
which provides access to global state in the IO monad.

Sebastian

[1] darcs repository, available under "Download" on
http://danae.uni-muenster.de/~lux/curry/
[2] http://www.informatik.uni-kiel.de/~pakcs/lib/CDOC/Global.html

On Wed, Sep 7, 2011 at 2:02 AM, Arthur Peters <amp4_at_pdx.edu> wrote:

> Hello there,
>
> I am currently working on writing a compiler from FlatCurry to OCaml
> (using an explicitly graph rewrite based evaluation engine). I am
> writing this compiler in curry (because there is a fairly nice
> FlatCurry lib). However I have run into a problem.
>
> I want to use a custom monad (a specialized state monad probably) for
> generating the OCaml code. And of course I want to use do notation
> to code with this monad. However I am getting errors like:
>
> "/home/amp/shared/school/
> Thesis/curry/State.curry", line 26.9: Type
> error in statement
> v <- return 2
>
> Term: return 2
> Inferred type: State _58 Prelude.Int
> Expected type: Prelude.IO _56
> Types Prelude.IO _56 and State _58 Prelude.Int are incompatible
>
> It seems that do notation only works with the IO monad. Is this the
> case? Is there any way around it or is this just what we are stuck
> with until curry gets type-classes? (which I know will be a long while
> because there is other more useful work to do on the language.)
>
> I'm pretty sure I could use IORefs to store the information I need in
> the IO monad but that seems like an ugly hack so I wanted to ask
> before I committed to that path.
>
> I am using PAKCS.
>
> -Arthur
>
> _______________________________________________
> curry mailing list
> curry_at_lists.RWTH-Aachen.DE
> http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
>
>



_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Wed Sep 07 2011 - 09:16:54 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 19 2019 - 07:15:08 CEST