From: skaller <skaller@users.sourceforge.net>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: nr@eecs.harvard.edu, caml-list@inria.fr
Subject: Re: [Caml-list] recursive polymorphic variants?
Date: Sat, 20 Aug 2005 21:57:19 +1000 [thread overview]
Message-ID: <1124539039.6850.20.camel@localhost.localdomain> (raw)
In-Reply-To: <20050819.065118.03980029.garrigue@math.nagoya-u.ac.jp>
[-- Attachment #1: Type: text/plain, Size: 2505 bytes --]
On Fri, 2005-08-19 at 06:51 +0900, Jacques Garrigue wrote:
> From: nr@eecs.harvard.edu (Norman Ramsey)
>
> > I'm trying to write a small, extensible interpreter, and I'd like to
> > use polymorphic variants as the extension mechanism.
> > Is there some way to define a recursive, *extensible* type using
> > polymorphic variants?
>
> "Code reuse through polymorphic variants" at
> http://www.math.nagoya-u.ac.jp/~garrigue/papers/
This paper is good but very skimpy .. :)
Open recursion is used, and types are inferred from functions.
It is possible to use the same techniques to define the
required types explicitly too, basic Felix bound term type
definition uses this:
(** value typing *)
type 't b0typecode_t' =
[
| `BTYP_inst of bid_t * 't list
| `BTYP_tuple of 't list
| `BTYP_unitsum of int
| `BTYP_sum of 't list
| `BTYP_function of 't * 't
| `BTYP_pointer of 't
| `BTYP_lvalue of 't
| `BTYP_array of 't * 't
| `BTYP_void
| `BTYP_fix of int
| `BTYP_var of int
]
(** meta typing *)
type 't b1typecode_t' =
[
| `BTYP_apply of 't * 't
| `BTYP_typefun of (int * 't) list * 't * 't
| `BTYP_type
| `BTYP_type_tuple of 't list
| `BTYP_type_match of 't * ('t * 't) list
]
(** general typing *)
type 't btypecode_t' =
[
| 't b0typecode_t'
| 't b1typecode_t'
]
type b0typecode_t = 't b0typecode_t' as 't
type btypecode_t = 't btypecode_t' as 't
Unfortunately, whilst I could use this technique for many terms
other than typecodes, I haven't because it is somewhat clumbsy
to write out terms with all the required added parameters and
then close the recursions. For just one extension over one variable
we have a 1 parameter overhead in the type definitions, and 9 lines
for the closure.
Inference removes the need to write out the types, but it makes
debugging virtually impossible. In addition, type inference isn't
strong enough to deduce the "correct" typing for all expressions,
coercions are sometimes required, and in practice to write them
abbreviations are necessary.
Having warned you .. I would never go back to ordinary variants
after using polymorphic ones: Felix uses them almost exclusively,
and even though I don't use the features heavily, knowing that
it is possible to refine the typing later seems a major software
engineering plus.
--
John Skaller <skaller at users dot sourceforge dot net>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2005-08-20 1:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-18 21:27 Norman Ramsey
2005-08-18 21:51 ` [Caml-list] " Jacques Garrigue
2005-08-20 11:57 ` skaller [this message]
2005-08-20 13:23 ` Jon Harrop
2005-08-20 13:50 ` Alain Frisch
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=1124539039.6850.20.camel@localhost.localdomain \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
--cc=nr@eecs.harvard.edu \
/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