caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Parameterizing a function with a thread monad
@ 2012-10-22 22:09 Philippe Veber
  2012-10-22 23:52 ` Jeremy Yallop
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Veber @ 2012-10-22 22:09 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 406 bytes --]

Dear camlers,

A couple of libraries, like pgocaml for instance, define a functor over a
(monadic) thread implementation, like in the following:

module type Thread = sig
  type 'a t
  val return : 'a -> 'a t
  val bind : 'a t -> ('a -> 'b t) -> 'b t
end

module F(T : Thread) : sig
  val v : string -> string T.t
end

Is it possible to define F as a function (ie at the value level)?

Cheers,
  Philippe.

[-- Attachment #2: Type: text/html, Size: 519 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Parameterizing a function with a thread monad
  2012-10-22 22:09 [Caml-list] Parameterizing a function with a thread monad Philippe Veber
@ 2012-10-22 23:52 ` Jeremy Yallop
  2012-10-23  7:56   ` Gabriel Scherer
  2012-10-24 10:30   ` Philippe Veber
  0 siblings, 2 replies; 5+ messages in thread
From: Jeremy Yallop @ 2012-10-22 23:52 UTC (permalink / raw)
  To: Philippe Veber; +Cc: caml users

On 22 October 2012 23:09, Philippe Veber <philippe.veber@gmail.com> wrote:
> A couple of libraries, like pgocaml for instance, define a functor over a
> (monadic) thread implementation, like in the following:
>
> module type Thread = sig
>   type 'a t
>   val return : 'a -> 'a t
>   val bind : 'a t -> ('a -> 'b t) -> 'b t
> end
>
> module F(T : Thread) : sig
>   val v : string -> string T.t
> end
>
> Is it possible to define F as a function (ie at the value level)?

Yes!  Matías Giovannini has a blog post showing how to do just that:

http://alaska-kamtchatka.blogspot.co.uk/2011/09/higher-order-fun.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Parameterizing a function with a thread monad
  2012-10-22 23:52 ` Jeremy Yallop
@ 2012-10-23  7:56   ` Gabriel Scherer
  2012-10-24 10:45     ` Philippe Veber
  2012-10-24 10:30   ` Philippe Veber
  1 sibling, 1 reply; 5+ messages in thread
From: Gabriel Scherer @ 2012-10-23  7:56 UTC (permalink / raw)
  To: Philippe Veber, caml users

If you want to parametrize over arbitrary monads, the modularized
appraoch (using functors or first-class modules) is adapted. But note
that for more specialized needs different interfaces are possible. For
example, Daniel Bünzli experimented with explicit inversion of control
instead of parametrization by monadic library, to solve the problem of
being Lwt/Async/"event loop" agnostic:

  [Caml-list] Non-blocking IO interface design
  https://sympa.inria.fr/sympa/arc/caml-list/2012-04/msg00055.html

I'm not sure how this worked out in the end, but this may be worth
looking at if you're still at the general design step.

On Tue, Oct 23, 2012 at 1:52 AM, Jeremy Yallop <yallop@gmail.com> wrote:
> On 22 October 2012 23:09, Philippe Veber <philippe.veber@gmail.com> wrote:
>> A couple of libraries, like pgocaml for instance, define a functor over a
>> (monadic) thread implementation, like in the following:
>>
>> module type Thread = sig
>>   type 'a t
>>   val return : 'a -> 'a t
>>   val bind : 'a t -> ('a -> 'b t) -> 'b t
>> end
>>
>> module F(T : Thread) : sig
>>   val v : string -> string T.t
>> end
>>
>> Is it possible to define F as a function (ie at the value level)?
>
> Yes!  Matías Giovannini has a blog post showing how to do just that:
>
> http://alaska-kamtchatka.blogspot.co.uk/2011/09/higher-order-fun.html
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Parameterizing a function with a thread monad
  2012-10-22 23:52 ` Jeremy Yallop
  2012-10-23  7:56   ` Gabriel Scherer
@ 2012-10-24 10:30   ` Philippe Veber
  1 sibling, 0 replies; 5+ messages in thread
From: Philippe Veber @ 2012-10-24 10:30 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]

2012/10/23 Jeremy Yallop <yallop@gmail.com>

> On 22 October 2012 23:09, Philippe Veber <philippe.veber@gmail.com> wrote:
> > A couple of libraries, like pgocaml for instance, define a functor over a
> > (monadic) thread implementation, like in the following:
> >
> > module type Thread = sig
> >   type 'a t
> >   val return : 'a -> 'a t
> >   val bind : 'a t -> ('a -> 'b t) -> 'b t
> > end
> >
> > module F(T : Thread) : sig
> >   val v : string -> string T.t
> > end
> >
> > Is it possible to define F as a function (ie at the value level)?
>
> Yes!  Matías Giovannini has a blog post showing how to do just that:
>
> http://alaska-kamtchatka.blogspot.co.uk/2011/09/higher-order-fun.html
>

Thanks a lot Jeremy, this is indeed exactly what I was looking for! I
suppose this (clever) representation has a cost at run-time. Maybe it'd be
worth to investigate it, as a typical monadic computation will use a lot of
bind/return operations. I'll try to have a look at it. Thanks again!

[-- Attachment #2: Type: text/html, Size: 1598 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Parameterizing a function with a thread monad
  2012-10-23  7:56   ` Gabriel Scherer
@ 2012-10-24 10:45     ` Philippe Veber
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Veber @ 2012-10-24 10:45 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 1959 bytes --]

Hi Gabriel,

well thanks, I had forgotten this interesting approach by Daniel. Indeed
for now I'd like to try a functor/first-class module -based solution.
Thanks for the suggestion anyway!
Cheers,
  ph.

2012/10/23 Gabriel Scherer <gabriel.scherer@gmail.com>

> If you want to parametrize over arbitrary monads, the modularized
> appraoch (using functors or first-class modules) is adapted. But note
> that for more specialized needs different interfaces are possible. For
> example, Daniel Bünzli experimented with explicit inversion of control
> instead of parametrization by monadic library, to solve the problem of
> being Lwt/Async/"event loop" agnostic:
>
>   [Caml-list] Non-blocking IO interface design
>   https://sympa.inria.fr/sympa/arc/caml-list/2012-04/msg00055.html
>
> I'm not sure how this worked out in the end, but this may be worth
> looking at if you're still at the general design step.
>
> On Tue, Oct 23, 2012 at 1:52 AM, Jeremy Yallop <yallop@gmail.com> wrote:
> > On 22 October 2012 23:09, Philippe Veber <philippe.veber@gmail.com>
> wrote:
> >> A couple of libraries, like pgocaml for instance, define a functor over
> a
> >> (monadic) thread implementation, like in the following:
> >>
> >> module type Thread = sig
> >>   type 'a t
> >>   val return : 'a -> 'a t
> >>   val bind : 'a t -> ('a -> 'b t) -> 'b t
> >> end
> >>
> >> module F(T : Thread) : sig
> >>   val v : string -> string T.t
> >> end
> >>
> >> Is it possible to define F as a function (ie at the value level)?
> >
> > Yes!  Matías Giovannini has a blog post showing how to do just that:
> >
> > http://alaska-kamtchatka.blogspot.co.uk/2011/09/higher-order-fun.html
> >
> > --
> > Caml-list mailing list.  Subscription management and archives:
> > https://sympa.inria.fr/sympa/arc/caml-list
> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> > Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 3079 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-24 10:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-22 22:09 [Caml-list] Parameterizing a function with a thread monad Philippe Veber
2012-10-22 23:52 ` Jeremy Yallop
2012-10-23  7:56   ` Gabriel Scherer
2012-10-24 10:45     ` Philippe Veber
2012-10-24 10:30   ` Philippe Veber

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).