2012/10/23 Jeremy Yallop > On 22 October 2012 23:09, Philippe Veber 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!