caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] extending user-defined polymorphic variant types
@ 2012-05-07  9:40 Dan Bensen
  2012-05-07 11:37 ` Philippe Veber
  2012-05-07 16:47 ` Goswin von Brederlow
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Bensen @ 2012-05-07  9:40 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]


I'm trying to write a functor that extends a user-supplied polymorphic 
variant type (PVT).  How do you declare the user's type in the signature 
for the argument to the functor without locking in the individual variant 
definitions?  
The code below (in revised syntax) generates an error message that says
the type isn't a PVT.

code:

> module type Reader = sig type ast; end;
>
> module Make (Read: Reader) = struct
>   type ast = [= Read.ast | `Lid of string];
> end;

message:

> Error: The type Read.ast is not a polymorphic variant type

How do you make ast a PVT while allowing the user to 
specify the variants?

[-- Attachment #2: Type: text/html, Size: 925 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extending user-defined polymorphic variant types
  2012-05-07  9:40 [Caml-list] extending user-defined polymorphic variant types Dan Bensen
@ 2012-05-07 11:37 ` Philippe Veber
  2012-05-07 16:47 ` Goswin von Brederlow
  1 sibling, 0 replies; 5+ messages in thread
From: Philippe Veber @ 2012-05-07 11:37 UTC (permalink / raw)
  To: Dan Bensen; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1066 bytes --]

Hi Dan,

I'm afraid you can't. If you want to write unions of polymorphic variant
types, they have to be concrete and not abstract. See Romain Bardou's work
on this:

http://romain.bardou.fr/papers/stage2006p.pdf

Or, if you can read french:

www.math.nagoya-u.ac.jp/~garrigue/papers/index.html

(see Unions de variants polymorphes abstraits).

Cheers,
  Philippe.



2012/5/7 Dan Bensen <danbensen@att.net>

>
> I'm trying to write a functor that extends a user-supplied polymorphic
> variant type (PVT).  How do you declare the user's type in the signature
> for the argument to the functor without locking in the individual variant
> definitions?
> The code below (in revised syntax) generates an error message that says
> the type isn't a PVT.
>
> code:
>
> > module type Reader = sig type ast; end;
> >
> > module Make (Read: Reader) = struct
> >   type ast = [= Read.ast | `Lid of string];
> > end;
>
> message:
>
> > Error: The type Read.ast is not a polymorphic variant type
>
> How do you make ast a PVT while allowing the user to
> specify the variants?
>

[-- Attachment #2: Type: text/html, Size: 1702 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extending user-defined polymorphic variant types
  2012-05-07  9:40 [Caml-list] extending user-defined polymorphic variant types Dan Bensen
  2012-05-07 11:37 ` Philippe Veber
@ 2012-05-07 16:47 ` Goswin von Brederlow
  2012-05-07 18:55   ` Dan Bensen
  1 sibling, 1 reply; 5+ messages in thread
From: Goswin von Brederlow @ 2012-05-07 16:47 UTC (permalink / raw)
  To: Dan Bensen; +Cc: caml-list

Dan Bensen <danbensen@att.net> writes:

> I'm trying to write a functor that extends a user-supplied polymorphic
> variant type (PVT).  How do you declare the user's type in the signature
> for the argument to the functor without locking in the individual variant
> definitions? 
> The code below (in revised syntax) generates an error message that says
> the type isn't a PVT.
>
> code:
>
>> module type Reader = sig type ast; end;
>>
>> module Make (Read: Reader) = struct
>>   type ast = [= Read.ast | `Lid of string];
>> end;
>
> message:
>
>> Error: The type Read.ast is not a polymorphic variant type
>
> How do you make ast a PVT while allowing the user to
> specify the variants?

Even if that did work how usefull would that be? You couldn't write

let foo = function
  | `Lid s -> ()
  | x -> Read.foo x

unless Read.foo allows [> Read.ast]. In which case you don't need a
functor but can just implement foo straight up.

What is your use case? What do you want to do?

MfG
        Goswin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extending user-defined polymorphic variant types
  2012-05-07 16:47 ` Goswin von Brederlow
@ 2012-05-07 18:55   ` Dan Bensen
  2012-05-07 20:17     ` Dan Bensen
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Bensen @ 2012-05-07 18:55 UTC (permalink / raw)
  To: Goswin von Brederlow; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 480 bytes --]


> What is your use case? What do you want to do?

I've been trying to combine camlp4 with OMeta.
(http://tinlizzie.org/ometa/)
The idea is to allow the user to extend the concrete 
syntax of the parsing system itself for parsing 
different kinds of data (terminals), then layer the 
standard combinator syntax on top of it.  

Maybe the user can define a regular variant type for
terminals and the combinator ast type can wrap it in 
a single variant (e.g. `Reader of Read.ast).

[-- Attachment #2: Type: text/html, Size: 788 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] extending user-defined polymorphic variant types
  2012-05-07 18:55   ` Dan Bensen
@ 2012-05-07 20:17     ` Dan Bensen
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Bensen @ 2012-05-07 20:17 UTC (permalink / raw)
  To: Dan Bensen, Goswin von Brederlow; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

> extend the concrete syntax of the parsing system
> itself for parsing different kinds of data (terminals),

> then layer the standard combinator syntax on top of it.

That last part should read "layer the standard 
combinator ast on top of the reader ast."

[-- Attachment #2: Type: text/html, Size: 686 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-07 20:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-07  9:40 [Caml-list] extending user-defined polymorphic variant types Dan Bensen
2012-05-07 11:37 ` Philippe Veber
2012-05-07 16:47 ` Goswin von Brederlow
2012-05-07 18:55   ` Dan Bensen
2012-05-07 20:17     ` Dan Bensen

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).