[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [MirageOS-devel] Cohttp Design -- LWT, Async, JS, Mirage Compatibility
Hi, While I do not have any particular criticism of cohttp, there is another approach to this problem that I personally find far more elegant and flexible. I will talk mostly of how to handle IO, but the same approach works with any type of "layering". Let us call it the "functor-less" approach. The main difference is that, while functors areÂused to parametrise the IO operations used *in* the code (often by way of defining an enclosing monad), the functor-less approach takes the IO completely *out* of the code. Instead IO actions are returned as values that guide the actions of particular backends. This involves formulating the sequencing of IO actions as a state machine. Rather than trying to explain the general setup, let me point to some well-known examples, which I hope will convey the essenceÂof this approach: - ocaml-tls (purelyÂfunctional style) (Unix backend) <https://github.com/dbuenzli/uutf/blob/master/src/uutf.mli#L446> Some advantages of this approach: - using functors require following a greatest common divisor design - the argument signature has to account for all relevant features of each backend, whether they are relevant or not for a particular one. Similarly, adding a new feature to a backend in the functorised approach often means giving an interpretation of this feature to all other backends, even if it does not make much sense. - by construction it completely decouplesÂIO and the program logic. The advantages of this with respect to clarity, error handling, safety, testing,Âare hard to overestimate. - do not have to write code in monadic style Best wishes, Nicolas On Sat, Mar 28, 2015 at 4:36 PM, Anil Madhavapeddy <anil@xxxxxxxxxx> wrote:
_______________________________________________ MirageOS-devel mailing list MirageOS-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |