Making Async play better with others

Yaron Minsky yminsky at gmail.com
Tue Nov 22 03:35:36 GMT 2011


So I guess that would mean ripping the Linux_ext module out of Core, right?

While I agree about keeping conditional code localized and small, I don't
quite see why the right answer is to have zero tolerance for conditional
compilation of OCaml.  Imagine that you have different APIs on different
platforms that require non-trivially different logic.  Now you're wedded to
the idea of having non-trivial code that compiles conditionally.  The only
question is, will you write that code in C or in OCaml?  Given that choice,
I usually choose OCaml...

Another way of dealing with some of these things is with runtime-tests that
key-off of the platform, potentially using first-class modules.  i.e., you
could have a value of the type:

val os : [ `Windows of (module Windows_specific_API)
         | `Linux   of (module Linux_specific_API)
         | `BSD     of (module BSD_specific_API)
         | `Posix   of (module Posix_specific_API) ]

The obvious downside is that it's a bit slower to dispatch your code, but
if you're doing a system call, maybe that doesn't matter.  And it has the
nice property that all of your OCaml code is type-checked all the time.
 You would just need some conditional compilation that chose the value of
`os` at compile-time.  The upside is that it gives you a way of writing
cross-platform programs that take advantage of the extra functionality when
it's present.

y

On Mon, Nov 21, 2011 at 10:22 PM, Stephen Weeks <sweeks at janestreet.com>wrote:

>
> > Stephen, what do you think about Markus' proposal for how to organize
> > it?
>
> I am highly skeptical of the approach of propagating Linux submodules and
> conditional compilation throughout the codebase.  I think it would be
> preferable
> to design a platform-agnostic interface at the OCaml/C boundary,
> implemented on
> the C side using platform-specific C files with minimal conditional
> compilation
> at the C level and no conditional compilation at the OCaml level.
>  Platforms
> that are unable to implement particular aspects of the interfaces should
> provide
> functions that raise exceptions.  Then all OCaml code compiles everywhere,
> and
> it one gets on each platform the maximum ability to run what is actually
> implemented.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/core/attachments/20111121/5aad5d68/attachment-0001.html>


More information about the core mailing list