[Haskell-beginners] Relation between Effects, Indexed monads, Free monads (PY)

鲍凯文 traqueofziche at gmail.com
Thu Nov 16 02:29:08 UTC 2017


Hi,

Disclaimer: I am not a lawyer. Nor do I claim to understand all this stuff.

The enforcement of sequential ordering is sort of baked into monads; the
haskell (read: do-notation) way of combining monadic computations is using
bind (i.e. in the "fancy list of instructions with a way to bind results").
This is only for the structure of the computation, though. Every monadic
computation is still a pure function, so in the end the RTS, well, executes
parts of those at a time, just as pure functions.

The ordering guarantee that more corresponds to imperative programming is
most obvious (to me) with ST, IO, and State; data dependencies ensure that
things "later" in the monadic chain cannot be executed until everything
"before". But those effects all involve (mutable) state. Monadic chaining,
i.e. combining effectful computations, is separate from the concept of
mutable state, etc. It seems more like just an algebra for effects.

If you're talking about marked monads as in those with extra type
information or phantom params, like when used in tandem with the rank-2
type trick (used in ST, region-based IO, etc.), I think that's a little
different, or at least beyond what monads are. Those were created to handle
things like guaranteeing that state is only modified single-threadedly
(ST), or to ensure that you can't do things like forget to close a handle
or leak a ref to a closed one (regions).

I think Free monads and (Kiselyov's) Eff monad are still different. They
still appeal to the "monads as sequence of instructions" view, but uh,
especially with the Eff monad, they're pretty fancy. As in at least
personally, for "normal" programming, I haven't felt the need to delve into
them.

I think the important upshot is: what are you working on? Do monadic
computations model what you want to do naturally? If they do, do you need
something stronger than what they provide? It's hard to answer the latter
questions without answering the first.

Sorry for rambling,

toz

On Wed, Nov 15, 2017 at 4:00 AM, <beginners-request at haskell.org> wrote:

> Send Beginners mailing list submissions to
>         beginners at haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
>         beginners-request at haskell.org
>
> You can reach the person managing the list at
>         beginners-owner at haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1.  Relation between Effects, Indexed monads,        Free monads (PY)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 15 Nov 2017 14:15:13 +0200
> From: PY <aquagnu at gmail.com>
> To: beginners at haskell.org
> Subject: [Haskell-beginners] Relation between Effects, Indexed monads,
>         Free monads
> Message-ID: <f34c805e-bad4-845e-d09b-43d9a9baea13 at gmail.com>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Hello, All!
>
> I'm not sure is it question for Cafe or Beginners List, so first I'll
> try here.
>
> There are kind of errors related to wrong execution sequence. They are
> good known in OOP: object keeps state internally and check it before to
> execute got message - to prevent wrong execution sequence. Best
> implementation is: state machine, also can be used Markov's algorithm,
> more complex can be done with Petri nets, etc.
>
> Example: if I have complex inserting into DB (consisting of several
> inserts), I can check done of previous step before to start next, etc.
> After read of different Haskell resources I found solution for it:
> Indexed Monads. They (if I got it rightly) are monads with additional
> type parameter which "marks" monad, gives it more specific
> qualification, for example instead of monad "Opening" (action) we have
> monad "Opening-of-closed", exactly what I'm talking: type-level check of
> correct actions sequence (allowed transition).
>
> After more research I found Free Monads and Effects and something like
> "free monad can be used to proof your program". How?! Free monads  make
> "active" (executable) code into "passive" code (data instead of code),
> which can be interpreted separately, so program becomes like Lisp
> program: code is a data (so, can be modified, checked, etc, etc) and
> what exactly will be executing - decides interpreter of such code. But
> do they allow to proof right sequence of actions in such data-like code?
>
> What are the Effects I don't understand yet.
>
> Somewhere I find something like: Eff = Free Monad + indexed monad (may
> be I'm not right here). So  my questions are:
>
> - how Effects, Free Monad, Indexed Monads are related?
>
> - can effects replace indexed monads?
>
> - are indexed monad yet usable/modern concept or they are abandoned and
> replaced by Effects or something else? Do you use indexed monads in real
> projects?
>
> - can I (and how) to use both of them? Or: can I use only FreeMonads /
> Effects to solve the same problem (control of correct sequence of
> actions) like with indexed monads help?
>
>
> ===
>
> Best regards, Paul
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 113, Issue 10
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171115/06bae7ea/attachment-0001.html>


More information about the Beginners mailing list