From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Till Varoquaux" <till.varoquaux@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>,
"Gérard Huet" <Gerard.Huet@inria.fr>,
"Benoit Razet" <Benoit.Razet@inria.fr>
Subject: Re: Abstract types in the revised syntax
Date: Thu, 3 May 2007 18:06:43 +0200 [thread overview]
Message-ID: <cd67f63a0705030906h387c710euf6728c0c22b73c03@mail.gmail.com> (raw)
In-Reply-To: <9d3ec8300705030848h7395c26eq5fd6bd2e8942762b@mail.gmail.com>
On 5/3/07, Till Varoquaux <till.varoquaux@gmail.com> wrote:
> I happen to very much dislike dangling free variables and therefore
> think this would be a nice improvement.
> Thanks for fixing my constraint issues.
> BTW I still haven't figured out how to generate constraints (lets say
> I have a list of strings [t1,..,tn] and a list of idents [c1...cn],
> how do I generate the type < c1:t1; ... ; cn:tn >? )
That way...
open Camlp4.PreCast;;
let mk_obj_type _loc fields types =
let object_type =
List.fold_right2 begin fun field typ object_type ->
<:ctyp< $lid:field$ : $lid:typ$ ; $object_type$ >>
end fields types <:ctyp<>>
in
<:ctyp< < $object_type$ > >>
;;
mk_obj_type (Loc.mk "<test>") ["f1"; "f2"] ["t1"; "t2"];;
>
> Cheers,
> Till
>
> On 5/3/07, Nicolas Pouillard <nicolas.pouillard@gmail.com> wrote:
> > Hello,
> >
> > This message concern the few people that use the revised syntax :)
> >
> > In the revised syntax, abstract types are expressed by defining them
> > with an unbound type variable:
> >
> > (* Original *)
> > type t;;
> >
> > (* Revised *)
> > type t = 'a;
> >
> > The motivation is that looks like an existential type, which is a way
> > of seeing abstract types.
> >
> > However I found this motivation misapplied since it doesn't look like
> > an existential type, there is no exists keyword?!? (type t = exists
> > 'a. 'a;)
> >
> > It's like a hot-dog without sausage?!?
> >
> > In fact, consequences of that choice are worst. If forces the
> > parser/printer to do some semantical operation to convert back and
> > forth between syntaxes.
> >
> > type t 'a = 'a; (* not abstract *)
> >
> > type t 'a = 'b; (* abstract *)
> >
> > It was considered acceptable, since the test for the freeness of a
> > single type variable seemed simple because very local.
> >
> > Indeed only the list of parameters was consulted to compute the
> > freeness of the type variable.
> >
> > It seems very weak since highly dependent of future evolution of the language.
> >
> > Nowadays it's no longer sufficient. Constraints can be added with a
> > type declaration to constrain the type of parameters.
> >
> > type c 'a = 'b
> > constraint 'a = < b : 'b; .. >;
> > (* Thanks to Till Varoquaux for it's bug report. *)
> >
> > Clearly I don't want to push that wrong choice further by making more
> > semantic analysis in the parser/printer.
> >
> > So I revert back to << type t; >> for abstract types.
> >
> > Now, what's the new representation for abstract types. OCaml use a
> > option type, where None represent the abstract type. We can't afford
> > that, since we want a concrete syntax for everything.
> > However we have a nil type that can be used as a default case (for
> > lists of types or optional types).
> >
> > <:sig_item< type t >> === <:sig_item< type t = $ <:ctyp<>> $ >>
> >
> > Not that this will also concern abstract module types.
> >
> > Alas, this will affect existing code using the revised syntax, but
> > will be easily caught at compilation.
> >
> > From a pragmatic point of view, a grep to show the usage of such types:
> > grep -E "^[ \t]*type.*=[ \t]*'[^ \t]*[ \t]*;[ \t]*$" **/*.ml*
> >
> > Feel free to share your mind on that subject. The change is not yet
> > applied to the CVS.
> >
> > Best regards,
> >
> > --
> > Nicolas Pouillard
> >
>
--
Nicolas Pouillard
next prev parent reply other threads:[~2007-05-03 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-03 11:39 Nicolas Pouillard
2007-05-03 15:48 ` Till Varoquaux
2007-05-03 16:06 ` Nicolas Pouillard [this message]
2007-05-03 16:39 ` Till Varoquaux
2007-05-10 20:37 ` Nicolas Pouillard
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=cd67f63a0705030906h387c710euf6728c0c22b73c03@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=Benoit.Razet@inria.fr \
--cc=Gerard.Huet@inria.fr \
--cc=caml-list@inria.fr \
--cc=till.varoquaux@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