caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kaspar Rohrer <kaspar.rohrer@gmail.com>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Functions over polymorphic variants
Date: Tue, 23 Mar 2010 20:46:15 +0100	[thread overview]
Message-ID: <50CAC2F1-D72F-49A1-B314-181B4C934437@gmail.com> (raw)
In-Reply-To: <20100323.151140.125875815.garrigue@math.nagoya-u.ac.jp>

Thank you for your concise answer. Am I correct when I say you are the author of the polymorphic variants and labels extension to OCaml?
As I stated earlier, I'm working somewhat heavily with PVs at the moment. One thing that bothers me is the error message for PV type mismatches.
As the PV types contain more than just a few tags, it becomes harder to identify the missing/different tags.

To come to the point: How hard would it be to patch the OCaml sources so that PV type mismatches would identify the offending tags?

To illustrate:

       Type declarations do not match:
         type input =
             [ `break
             | `fragment of string
             | `linebreak
             | `newline
             | `nop
             | `set_background of color
             | `set_context of context
             | `set_foreground of color
             | `set_intensity of intensity
             | `set_inverted of bool
             | `set_justification of justification
             | `set_underline of underline
             | `set_width of int
             | `space of int ]
       is not included in
         type input =
             [ `break
             | `fragment of string
             | `linebreak
             | `newline
             | `nop
             | `set_background of color
             | `set_context of context
             | `set_foreground of color
             | `set_intensity of intensity
             | `set_inverted of bool
             | `set_underline of underline
             | `space of int ]

Maybe the common tags could be omitted in a final digest:

       Type mismatch:
         type input =
             [ ...
             | `set_justification of justification
             | `set_width of int ]
       is not included in
         type input =
             [ ... ]

I guess open and closed PV types would complicate things a bit, but this should be possible, right?

Thank you

----
Kaspar Rohrer
kaspar.rohrer@gmail.com

On Mar 23, 2010, at 7:11 AM, Jacques Garrigue wrote:

> From: Kaspar Rohrer <kaspar.rohrer@gmail.com>
>> I am tinkering with streams of polymorphic variants at the
>> moment. One thing that I would like to do is to write a stream
>> transformer (not sure this is the correct terminology) that simply
>> drops certain values of an open polymorphic type, and have the type
>> of the function reflect this.
> 
> Sorry, you can't.
> This is a design choice with ocaml polymorphic variants, that the row
> variable is kept hidden. This has the advantage of simplicity, but it
> makes impossible to abstract on the row variable itself, like you want
> here.
> 
>> This is trivial with a closed polymorphic type:
>> 
>> type abc = [`a | `b | `c]
>> 
>> let transform (stream : [< `x | abc] Stream.t) : [> abc] Stream.t =
>> let rec fold () =
>>     match Stream.next stream with
>> 	| `x -> Stream.slazy fold
>> 	| #abc as x -> Stream.icons x (Stream.slazy fold)
>>   with
>> 	Stream.Failure -> Stream.sempty
>> in
>>   fold ()
>> 
>> However, I fail to see how the same function could be implemented so it accepts an open polymorphic type as it's input.
>> I.e. is there a way to express something like this (which is not valid OCaml)
>> 
>> let transform : [> `x | 'a] Stream.t -> [> 'a] Stream.t
>> 
>> Does this even make sense?
> 
> This makes sense, but would require a different type system.
> With ocaml, you must keep to closed types.
> This should be sufficient for concrete examples, but you cannot build
> polymorphic combinators.
> 
> Note. In designing a type system where you would be able to express
> such "differential" types, poinder the problem: what is the type of
> transform composed with itself.
> 
> Jacques Garrigue


      reply	other threads:[~2010-03-23 19:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23  2:53 Kaspar Rohrer
2010-03-23  6:11 ` [Caml-list] " Jacques Garrigue
2010-03-23 19:46   ` Kaspar Rohrer [this message]

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=50CAC2F1-D72F-49A1-B314-181B4C934437@gmail.com \
    --to=kaspar.rohrer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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;
as well as URLs for NNTP newsgroup(s).