From: Ivan Gotovchits <ivg@ieee.org>
To: Didier Cassirame <didier.cassirame@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Higher order functors over tuples
Date: Wed, 31 Oct 2012 16:02:30 +0400 [thread overview]
Message-ID: <87txtahmsp.fsf@golf.niidar.ru> (raw)
In-Reply-To: <CA+LkvyrPzuOo5dMnOHDzn1zWg6Lya9k6Ym6Wz6qJQQLYq6q6ZA@mail.gmail.com> (Didier Cassirame's message of "Wed, 31 Oct 2012 12:09:09 +0100")
Didier Cassirame <didier.cassirame@gmail.com> writes:
> Do you wish to have parallel computation done with these modules, or
> do you mean that you want them to be combined sequentially?
Ideally, computation must be combined arbitrary. It will be nice to have
MAP functor, or MAP2 functor, etc.
> Thanks to a very recent post, I rediscovered that OCaml can handle modules as first class values (since ver. 3.12) :
>
> - you can define types based on module types like this.
>
> module type M = sig ... end
>
> type m = (module M)
>
> and then you should be able to build simple lists of type m.
I've heard that it is possible, but unfortunately I'm stucked with 3.11
;'( And I'm not still sure that it will work. Need to try it myself =)
> 3) My intution says that it can be solved with monads (Generator really
> incapsulates side effects in a step. Several computation are combined in
> one big chain... ). Am I right? If so, how to implement it in monads?
>
> I guess that you could use the type above with regular monads too.
Hmmm, the problem is that I do not understand monads quite well. So I've
solved the task in a «my» way. And so I want to know how the problem can
(and could it?) be solved with monads, which are considered a common and
idiomatic way of solving such problems.
>
> If you don't have access to that feature, you could perhaps use higher order functors?
I do use them. I generate a list of modules using higher order
functor. For example I build structure of modules [Even, Odd, Even, Odd]
with
module M = Cons(Even)(Cons(Odd)(Cons(Even)(Odd)))
Calling ``let m = M.create ()'' will build some structure of objects of different
types. (Their can be more two types of modules). A call to ``M.step m''
will apply ``Even.step'' or ``Odd.step'' to the last objects in a list,
and move it to the head. A call ``M.result m'' will return the
result of calling ``Even.result m'' or ``Odd.result m'' dependingly on a
current type in head of list.
--
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
...."Have you mooed today?"...
next prev parent reply other threads:[~2012-10-31 11:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 9:26 Ivan Gotovchits
2012-10-31 11:09 ` Didier Cassirame
2012-10-31 12:02 ` Ivan Gotovchits [this message]
2012-11-30 12:49 ` [Caml-list] ocamlc, ocamlopt stackoverflow on list Christophe Raffalli
2012-11-30 13:20 ` Gabriel Scherer
2012-11-30 13:31 ` Christophe Raffalli
2012-11-30 14:15 ` Gabriel Scherer
2012-11-06 11:48 [Caml-list] Higher order functors over tuples oleg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txtahmsp.fsf@golf.niidar.ru \
--to=ivg@ieee.org \
--cc=caml-list@inria.fr \
--cc=didier.cassirame@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).