* Generalized algebraic datatypes
@ 2008-04-28 5:35 Jacques Le Normand
2008-04-28 6:50 ` [Caml-list] " Gabriel Kerneis
0 siblings, 1 reply; 7+ messages in thread
From: Jacques Le Normand @ 2008-04-28 5:35 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 322 bytes --]
Dear caml-list,
I'm writing a toy compiler that compiles into ocaml and my toy compiler
supports Generalized Algebraic Datatypes, so I need to compile into a
language which also supports them.
Does ocaml support Generalized Algebraic datatypes? If not, are there any
caml based compilers that support it?
cheers
--Jacques
[-- Attachment #2: Type: text/html, Size: 343 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Generalized algebraic datatypes
2008-04-28 5:35 Generalized algebraic datatypes Jacques Le Normand
@ 2008-04-28 6:50 ` Gabriel Kerneis
0 siblings, 0 replies; 7+ messages in thread
From: Gabriel Kerneis @ 2008-04-28 6:50 UTC (permalink / raw)
To: Jacques Le Normand; +Cc: caml-list
On Mon, Apr 28, 2008 at 01:35:06AM -0400, Jacques Le Normand wrote:
> Does ocaml support Generalized Algebraic datatypes?
No.
> If not, are there any caml based compilers that support it?
Some pieces of software (e.g. Ocsigen), which need GADT, use (very
carefuly crafted) "black magic" (Obj.magic) to get things compiled.
You could probably do this in your "toy compiler", put you will loose
the benefit of Ocaml's type-checking.
Regards,
--
Gabriel Kerneis
^ permalink raw reply [flat|nested] 7+ messages in thread
* Generalized Algebraic Datatypes
@ 2010-10-25 8:39 Jacques Le Normand
0 siblings, 0 replies; 7+ messages in thread
From: Jacques Le Normand @ 2010-10-25 8:39 UTC (permalink / raw)
To: caml-list caml-list
[-- Attachment #1: Type: text/plain, Size: 422 bytes --]
Dear Caml list,
I am pleased to announce an experimental branch of the O'Caml compiler:
O'Caml extended with Generalized Algebraic Datatypes. You can find more
information on this webpage:
https://sites.google.com/site/ocamlgadt/
And you can grab the latest release here:
svn checkout https://yquem.inria.fr/caml/svn/ocaml/branches/gadts
Any feedback would be very much appreciated.
Sincerely,
Jacques Le Normand
[-- Attachment #2: Type: text/html, Size: 1266 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Generalized Algebraic Datatypes
@ 2010-10-29 14:32 Dario Teixeira
2010-10-29 15:03 ` Jacques Le Normand
2010-10-29 21:10 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: Dario Teixeira @ 2010-10-29 14:32 UTC (permalink / raw)
To: caml-list, Jacques Le Normand
Hi,
> I am pleased to announce an experimental branch of the O'Caml compiler:
> O'Caml extended with Generalized Algebraic Datatypes. You can find more
> information on this webpage:
I have a couple of questions regarding the syntax you've chosen for GADT
declaration. For reference, let's consider the first example you've provided:
type _ t =
| IntLit : int -> int t
| BoolLit : bool -> bool t
| Pair : 'a t * 'b t -> ('a * 'b) t
| App : ('a -> 'b) t * 'a t -> 'b t
| Abs : ('a -> 'b) -> ('a -> 'b) t
There's something "Haskellish" about this syntax, in the sense that type
constructors are portrayed as being like functions. While this does make
sense in Haskell, in Ocaml it feels a bit out of place, because you cannot,
for example, partially apply a type constructor.
Also, note that in all the variant declarations the final token is 't'.
Are there any circumstances at all where a GADT constructor will not end
by referencing the type being defined? If there are not, then this syntax
imposes some syntactic salt into the GADT declaration.
I know this is not the sole syntax that was considered for GADTs in Ocaml.
Xavier Leroy's presentation in CUG 2008 shows a different one, which even
though slightly more verbose, does have the advantage of being more "Camlish".
Is there any shortcoming to the 2008 syntax that resulted in it being dropped
in favour of this new one?
Best regards,
Dario Teixeira
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Generalized Algebraic Datatypes
2010-10-29 14:32 [Caml-list] " Dario Teixeira
@ 2010-10-29 15:03 ` Jacques Le Normand
2010-10-29 15:19 ` Sylvain Le Gall
2010-10-29 21:10 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: Jacques Le Normand @ 2010-10-29 15:03 UTC (permalink / raw)
To: Dario Teixeira; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 1683 bytes --]
Hello,
I didn't know about this alternate syntax; can you please describe it?
cheers
--Jacques
On Fri, Oct 29, 2010 at 10:32 AM, Dario Teixeira <darioteixeira@yahoo.com>wrote:
> Hi,
>
> > I am pleased to announce an experimental branch of the O'Caml compiler:
> > O'Caml extended with Generalized Algebraic Datatypes. You can find more
> > information on this webpage:
>
> I have a couple of questions regarding the syntax you've chosen for GADT
> declaration. For reference, let's consider the first example you've
> provided:
>
> type _ t =
> | IntLit : int -> int t
> | BoolLit : bool -> bool t
> | Pair : 'a t * 'b t -> ('a * 'b) t
> | App : ('a -> 'b) t * 'a t -> 'b t
> | Abs : ('a -> 'b) -> ('a -> 'b) t
>
>
> There's something "Haskellish" about this syntax, in the sense that type
> constructors are portrayed as being like functions. While this does make
> sense in Haskell, in Ocaml it feels a bit out of place, because you cannot,
> for example, partially apply a type constructor.
>
> Also, note that in all the variant declarations the final token is 't'.
> Are there any circumstances at all where a GADT constructor will not end
> by referencing the type being defined? If there are not, then this syntax
> imposes some syntactic salt into the GADT declaration.
>
> I know this is not the sole syntax that was considered for GADTs in Ocaml.
> Xavier Leroy's presentation in CUG 2008 shows a different one, which even
> though slightly more verbose, does have the advantage of being more
> "Camlish".
> Is there any shortcoming to the 2008 syntax that resulted in it being
> dropped
> in favour of this new one?
>
> Best regards,
> Dario Teixeira
>
>
>
>
>
[-- Attachment #2: Type: text/html, Size: 2305 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generalized Algebraic Datatypes
2010-10-29 14:32 [Caml-list] " Dario Teixeira
2010-10-29 15:03 ` Jacques Le Normand
@ 2010-10-29 21:10 ` Stefan Monnier
2010-10-29 21:37 ` [Caml-list] " bluestorm
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2010-10-29 21:10 UTC (permalink / raw)
To: caml-list
> type _ t =
> | IntLit : int -> int t
> | BoolLit : bool -> bool t
> | Pair : 'a t * 'b t -> ('a * 'b) t
> | App : ('a -> 'b) t * 'a t -> 'b t
> | Abs : ('a -> 'b) -> ('a -> 'b) t
> There's something "Haskellish" about this syntax, in the sense that type
> constructors are portrayed as being like functions.
Indeed IIRC OCaml does not accept "App" as an expression (you have to
provide arguments to the construct). Maybe this is a good opportunity
to lift this restriction.
> While this does make sense in Haskell, in Ocaml it feels a bit out of
> place, because you cannot, for example, partially apply
> a type constructor.
The types above don't allow partial applications either. They use the
OCaml/SML style of constructors were partial application is not possible
because the various arguments are not provided in a curried way.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Re: Generalized Algebraic Datatypes
2010-10-29 21:10 ` Stefan Monnier
@ 2010-10-29 21:37 ` bluestorm
2010-10-31 14:15 ` Wojciech Daniel Meyer
0 siblings, 1 reply; 7+ messages in thread
From: bluestorm @ 2010-10-29 21:37 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]
On Fri, Oct 29, 2010 at 11:10 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:
> > type _ t =
> > | IntLit : int -> int t
> > | BoolLit : bool -> bool t
> > | Pair : 'a t * 'b t -> ('a * 'b) t
> > | App : ('a -> 'b) t * 'a t -> 'b t
> > | Abs : ('a -> 'b) -> ('a -> 'b) t
>
> > There's something "Haskellish" about this syntax, in the sense that type
> > constructors are portrayed as being like functions.
>
> Indeed IIRC OCaml does not accept "App" as an expression (you have to
> provide arguments to the construct). Maybe this is a good opportunity
> to lift this restriction.
It was actually the case in Caml Light : each datatype constructor
implicitly declared a constructor function with the same name. I don't
exactly know why this feature was dropped in Objective Caml, but I think I
remember (from a previous discussion) that people weren't sure it was worth
the additional complexity.
Note that, as in Jacques's examples, the constructor function was not
curryfied. (type t = A of bool * int) would generate a function (A : bool *
int -> t). It doesn't help the already tricky confusion between (A of bool *
int) and (A of (bool * int))...
By the way, it is unclear if
| App : ('a -> 'b) t -> 'a t -> 'b t
would be accepted in Jacques proposal. If not, I think going back to a "of
..." syntax would be wiser.
[-- Attachment #2: Type: text/html, Size: 2044 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Re: Generalized Algebraic Datatypes
2010-10-29 21:37 ` [Caml-list] " bluestorm
@ 2010-10-31 14:15 ` Wojciech Daniel Meyer
2010-10-31 14:35 ` Sylvain Le Gall
0 siblings, 1 reply; 7+ messages in thread
From: Wojciech Daniel Meyer @ 2010-10-31 14:15 UTC (permalink / raw)
To: bluestorm; +Cc: caml-list
bluestorm <bluestorm.dylc@gmail.com> writes:
> It was actually the case in Caml Light : each datatype constructor
> implicitly declared a constructor function with the same name. I
> don't exactly know why this feature was dropped in Objective Caml,
> but I think I remember (from a previous discussion) that people
> weren't sure it was worth the additional complexity.
Would that be not possible now with Camlp4 extension?
Wojciech
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generalized Algebraic Datatypes
2010-10-31 14:15 ` Wojciech Daniel Meyer
@ 2010-10-31 14:35 ` Sylvain Le Gall
2010-10-31 14:49 ` [Caml-list] " Lukasz Stafiniak
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Le Gall @ 2010-10-31 14:35 UTC (permalink / raw)
To: caml-list
On 31-10-2010, Wojciech Daniel Meyer <wojciech.meyer@googlemail.com> wrote:
> bluestorm <bluestorm.dylc@gmail.com> writes:
>
>> It was actually the case in Caml Light : each datatype constructor
>> implicitly declared a constructor function with the same name. I
>> don't exactly know why this feature was dropped in Objective Caml,
>> but I think I remember (from a previous discussion) that people
>> weren't sure it was worth the additional complexity.
>
> Would that be not possible now with Camlp4 extension?
>
I am pretty sure, it is possible to implement them with camlp4. Just a
matter of time -- and motivation.
The only limitation I can see, is that the generated constructors won't
be capitalized. E.g.:
type t = MyConstr | YourConstr of int
=>
type t = MyConstr | YourConstr of int
let myConstr = MyConstr
let yourConstr i = YouConstr i
Regards,
Sylvain Le Gall
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Re: Generalized Algebraic Datatypes
2010-10-31 14:35 ` Sylvain Le Gall
@ 2010-10-31 14:49 ` Lukasz Stafiniak
2010-10-31 15:08 ` Sylvain Le Gall
0 siblings, 1 reply; 7+ messages in thread
From: Lukasz Stafiniak @ 2010-10-31 14:49 UTC (permalink / raw)
To: Sylvain Le Gall; +Cc: caml-list
On Sun, Oct 31, 2010 at 3:35 PM, Sylvain Le Gall <sylvain@le-gall.net> wrote:
> On 31-10-2010, Wojciech Daniel Meyer <wojciech.meyer@googlemail.com> wrote:
>> bluestorm <bluestorm.dylc@gmail.com> writes:
>>
>>> It was actually the case in Caml Light : each datatype constructor
>>> implicitly declared a constructor function with the same name. I
>>> don't exactly know why this feature was dropped in Objective Caml,
>>> but I think I remember (from a previous discussion) that people
>>> weren't sure it was worth the additional complexity.
>>
>> Would that be not possible now with Camlp4 extension?
>>
>
> I am pretty sure, it is possible to implement them with camlp4. Just a
> matter of time -- and motivation.
>
> The only limitation I can see, is that the generated constructors won't
> be capitalized. E.g.:
>
> type t = MyConstr | YourConstr of int
>
> =>
>
> type t = MyConstr | YourConstr of int
>
> let myConstr = MyConstr
> let yourConstr i = YouConstr i
>
Why do you say so? HOL Light uses capitalized identifiers for values,
for example. It's probably possible to do whatever one reasonably
wants.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generalized Algebraic Datatypes
2010-10-31 14:49 ` [Caml-list] " Lukasz Stafiniak
@ 2010-10-31 15:08 ` Sylvain Le Gall
0 siblings, 0 replies; 7+ messages in thread
From: Sylvain Le Gall @ 2010-10-31 15:08 UTC (permalink / raw)
To: caml-list
On 31-10-2010, Lukasz Stafiniak <lukstafi@gmail.com> wrote:
> On Sun, Oct 31, 2010 at 3:35 PM, Sylvain Le Gall <sylvain@le-gall.net> wrote:
>> On 31-10-2010, Wojciech Daniel Meyer <wojciech.meyer@googlemail.com> wrote:
>>> bluestorm <bluestorm.dylc@gmail.com> writes:
>>>
>>>> It was actually the case in Caml Light : each datatype constructor
>>>> implicitly declared a constructor function with the same name. I
>>>> don't exactly know why this feature was dropped in Objective Caml,
>>>> but I think I remember (from a previous discussion) that people
>>>> weren't sure it was worth the additional complexity.
>>>
>>> Would that be not possible now with Camlp4 extension?
>>>
>>
>> I am pretty sure, it is possible to implement them with camlp4. Just a
>> matter of time -- and motivation.
>>
>> The only limitation I can see, is that the generated constructors won't
>> be capitalized. E.g.:
>>
>> type t = MyConstr | YourConstr of int
>>
>> =>
>>
>> type t = MyConstr | YourConstr of int
>>
>> let myConstr = MyConstr
>> let yourConstr i = YouConstr i
>>
>
> Why do you say so? HOL Light uses capitalized identifiers for values,
> for example. It's probably possible to do whatever one reasonably
> wants.
>
Function names and values are "low id" in OCaml (first letter must be
uncapitalized). If you try to define "let MyConstr = 0" in an OCaml
toplevel, you will get a syntax error...
The code generated by camlp4 must be syntactically correct.
But maybe you are talking about a deeper integration?
E.g. whenever you encounter the constructor "YourConstr" in expr, you
transform it into "fun i -> YourConstr i". This should work but since
camlp4 is limited to a single module, you won't be able to use this
outside the module, because you won't have access to the definition of
YouConstr and won't be able to determine his arity...
But if you have an idea about how to solve this, just tell us.
Regards,
Sylvain Le Gall
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-10-31 15:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-28 5:35 Generalized algebraic datatypes Jacques Le Normand
2008-04-28 6:50 ` [Caml-list] " Gabriel Kerneis
2010-10-25 8:39 Generalized Algebraic Datatypes Jacques Le Normand
2010-10-29 14:32 [Caml-list] " Dario Teixeira
2010-10-29 15:03 ` Jacques Le Normand
2010-10-29 15:19 ` Sylvain Le Gall
2010-10-29 21:10 ` Stefan Monnier
2010-10-29 21:37 ` [Caml-list] " bluestorm
2010-10-31 14:15 ` Wojciech Daniel Meyer
2010-10-31 14:35 ` Sylvain Le Gall
2010-10-31 14:49 ` [Caml-list] " Lukasz Stafiniak
2010-10-31 15:08 ` Sylvain Le Gall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).