caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: j h woodyatt <jhw@conjury.org>
To: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
Cc: The Caml Trade <caml-list@inria.fr>
Subject: Re: Typing problem
Date: Sun, 19 Mar 2006 06:23:57 -0800	[thread overview]
Message-ID: <05965C1A-F9E5-4E62-8D74-C8314D55425C@conjury.org> (raw)

Daniel Bünzli <daniel.buenzli@epfl.ch>
>
> I would like to define the following types.
>
>> type u = [ `U1 | `U2 ]
>> type 'a t = [`A of 'a | `B of ([`U1 ] as 'a) ] constraint 'a = [< u ]
>
> t's parameter is used to statically express constraints in other  
> parts of the code. My problem is that the constraint on 'a is  
> downgraded to [`U1] while I would like to be able to write
>
>> let param : 'a t -> 'a = function (`A v | `B v) -> v
>
> and get the following typing behaviour.
>
>> let v = param (`A `U1) (* should type *)
>> let v = param (`A `U2) (* should type *)
>> let v = param (`B `U1) (* should type *)
>> let v = param (`B `U2) (* should not type *)
>
> Is it possible to express that in ocaml's type system ?

The short answer is no.  The reason is that 'a is not the same type  
in the `A case as in the `B case.  Type t really has two type  
parameters.  (Well, it can have only one if this contrived example is  
fully representative of your code, as I'll describe below).

type ('a, 'b) t = [ `A of 'a | `B of 'b ]
   constraint 'a = [< u ] constraint 'b = [ `U1 ]

However, 'b is concrete in your example, so-- if it's fully  
representative of your code-- you could just do this, and you would  
still have only one type parameter:

type 'a t = [ `A of 'a | `B of [ `U1 ] ]
   constraint 'a = [< u ]

—
j h woodyatt <jhw@conjury.org>




             reply	other threads:[~2006-03-19 14:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-19 14:23 j h woodyatt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-03-19  1:30 Daniel Bünzli
2000-02-10 13:49 jean-marc alliot
2000-02-11 10:17 ` Pierre Weis
2000-02-12 22:34   ` Jacques Garrigue

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=05965C1A-F9E5-4E62-8D74-C8314D55425C@conjury.org \
    --to=jhw@conjury.org \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@epfl.ch \
    --cc=ocaml-beginners@yahoogroups.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;
as well as URLs for NNTP newsgroup(s).