From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: David Teller <David.Teller@ens-lyon.org>, OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Deriving + type-conv + OCaml-Templates + camlp4* = ?
Date: Wed, 27 Feb 2008 10:56:59 +0000 [thread overview]
Message-ID: <47C541FB.30508@ed.ac.uk> (raw)
In-Reply-To: <f8560b80802261401pc08ad41v677dc016fec8544f@mail.gmail.com>
Markus Mottl wrote:
> On Tue, Feb 26, 2008 at 3:27 PM, David Teller
> <David.Teller@ens-lyon.org> wrote:
>> Browsing around the net, I've found three
>> "scrap-your-boilerplate"-style projects for OCaml: the simple
>> Type-conv, the ambitious Deriving and the unmaintained
>> OCaml-Templates, and of course the ability to use camlp4/camlp5 for
>> the same purpose. I imagine that there are a number of nice
>> boilerplate-based modules just waiting to be implemented or
>> adopted.
>>
>> As far as I understand, there's no interaction between the project
>> authors, which is a shame. So this is an open call to whoever is in
>> charge of each work: do you think it would be possible for you all
>> to join forces and produce something robust, simple and possible to
>> adopt as a standard ?
>
> I think that different projects have different trade-offs that are
> hard, if not impossible, to combine.
I fear that you may be right, although (as the author of deriving) I'd
be more than happy to consider collaboration, given a concrete proposal.
> Deriving is a very elegant, general approach, but last time I checked
> it would be hard to generate highly optimized code with it,
Thanks for the kind words! I expect you're right about generating
optimized code; as you suggest this hasn't been a focus. Performance of
generated code should be at least reasonable, though, and it is possible
to substitute handwritten code at critical points, as with any such
approach.
> and it was also not complete (e.g. handling hard cases like
> polymorphic variants with inherited types, etc.).
This is a little more surprising, since completeness *is* a focus of
deriving.
If I understand you rightly, then the case you mention is actually
handled: are you referring to using deriving with a polymorphic variant
type that extends another, such as
type a = [`A]
type ab = [a|`B]
?
This sort of thing is certainly handled; indeed, deriving handles
considerably more complicated cases as well, e.g. involving various
sorts of recursion:
type ('a,'b) x = [`One of 'a | `Two of 'b] deriving (Show)
type 'a y = [`Four of ([('z,'a) x | `Three] as 'z)] deriving (Show)
type z = z y deriving (Show)
let _ = print_endline (Show.show<z>
(`Four (`One (`Two (`Four `Three)))))
In fact, the way that deriving treats structural types with inline
recursion (i.e. the "as" syntax) is perhaps an example of a difficulty
in combining projects: deriving converts types into a normalized
representation in which this recursion is shifted to the type
declaration level: a sort of ANF for types. This works well (and makes
it much easier to write new generic functions, since it removes the need
to deal with "as"), but might be a little heavyweight for projects with
other focuses.
To avoid giving the impression that deriving is absolutely complete, I
should mention that nested (i.e. irregular) types are not handled. This
is in some ways a limitation of the approach of using modules for
recursion. I don't think this limitation is significant for most
people, but I may look into adding support at some point.
Jeremy.
next prev parent reply other threads:[~2008-02-27 11:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-26 20:27 David Teller
2008-02-26 22:01 ` [Caml-list] " Markus Mottl
2008-02-27 10:56 ` Jeremy Yallop [this message]
2008-02-28 18:17 ` Markus Mottl
2008-02-26 22:02 ` Till Varoquaux
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=47C541FB.30508@ed.ac.uk \
--to=jeremy.yallop@ed.ac.uk \
--cc=David.Teller@ens-lyon.org \
--cc=caml-list@inria.fr \
--cc=markus.mottl@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