caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Olivier Andrieu <andrieu@ijm.jussieu.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Two types of efficiency (Was Efficiency of 'a list)
Date: Mon, 05 May 2003 21:04:14 +1000	[thread overview]
Message-ID: <3EB6452E.8030100@ozemail.com.au> (raw)
In-Reply-To: <16052.65298.366652.327622@karryall.dnsalias.org>

Olivier Andrieu wrote:

>  John Max Skaller [Sunday 4 May 2003] :
>  > Similarly, subtyping of polymorphic variants is invariant
>  > in the arguments, when covariance is sound and more useful.
>  > This is a real pain for me, since it destroys the main use
>  > I hoped to obtain for polymorphic variants:
>  > 
>  > type x = [`A | `B of x]
>  > type y = [`A | `B of y | `C]
>  > 
>  > x *is* a subtype of y, but the type system
>  > disallows it, failing to recognise that every `B x
>  > of type x is also a `B y of y. Typically I have
>  > say a term for an expression and I want to eliminate
>  > some cases by say a term reduction, but I can't restrict
>  > the resultant type as desired because there's no way
>  > to 'narrow' the type recursion.
> 
> # type x = [`A | `B of x] ;;
> type x = [ `A | `B of x]
> # type y = [`A | `B of y | `C] ;;
> type y = [ `A | `B of y | `C]
> # fun a -> (a :x :> y) ;;
> - : x -> y = <fun>
> 
> Doesn't that mean that x is a subtype of y ?


Indeed. Hmm .. has this changed since 3.04?
[I just installed the CVS version which is 3.06+31 (2003/5/2)]
Let me try a more comprehensible example.


type expr1 = [`Prim | `Add of expr1 * expr1 | `Plus of expr1 * expr1]
type expr2 = [`Prim | `Add of expr2 * expr2]
let lift e = (e : expr2 :> expr1)
;;

let rec r (e:expr1): expr2 =
  match e with
  | `Prim -> `Prim
  | `Add (a,b) -> `Add (r a,r b)
  | `Plus (a,b) -> `Add (r a, r b)
;;

And it works. It didn't before!

So thx for pointing this out, and thx to the
ocaml team for doing this work.

Now I'll go off and try to use it.
It will simplify my code a lot: at present I have a lot
of cases I know won't occur, because they've been
"reduced out" by a prior term rewriting routine, but the typing
didn't allow this to be expressed. A lot of nasty

  | _ -> assert false

terms will be eliminated: getting rid of wildcard
matches should improve compile time error diagnosis
considerably. Kind of a pity I can't write:

type expr1 = [expr2 | `Plus expr1 * expr1]

but it would lift the wrong recursion out.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-05-05 11:04 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-02 19:27 [Caml-list] Efficiency of 'a list Eray Ozkural
2003-05-03  5:43 ` Mattias Waldau
2003-05-03  8:16   ` Ville-Pertti Keinonen
2003-05-03 14:12   ` Vitaly Lugovsky
2003-05-03 18:43     ` Mattias Waldau
2003-05-03 20:01       ` Eray Ozkural
2003-05-03 23:17       ` Eray Ozkural
2003-05-04  2:08       ` cashin
2003-05-04  4:08         ` alc
2003-05-04  5:32           ` Ed L Cashin
2003-05-04  6:46           ` [Caml-list] Two types of efficiency (Was Efficiency of 'a list) Mattias Waldau
2003-05-04  7:35             ` John Max Skaller
2003-05-04 11:52               ` Olivier Andrieu
2003-05-05 11:04                 ` John Max Skaller [this message]
2003-05-04 16:48               ` brogoff
2003-05-04  7:43             ` Ville-Pertti Keinonen
2003-05-04 12:50               ` Eray Ozkural
2003-05-04 12:48             ` Eray Ozkural
2003-05-05  7:31             ` Diego Olivier Fernandez Pons
2003-05-05 11:11               ` Mattias Waldau
2003-05-05 13:17                 ` John Max Skaller
2003-05-05 11:49               ` Eray Ozkural
2003-05-05 11:57               ` Yaron M. Minsky
2003-05-05 13:32                 ` John Max Skaller
2003-05-06  2:49                   ` Nicolas Cannasse
2003-05-06 12:30                     ` Diego Olivier Fernandez Pons
2003-05-07  2:05                       ` Nicolas Cannasse
2003-05-05 16:38                 ` Diego Olivier Fernandez Pons
2003-05-05 18:05                   ` Eray Ozkural
2003-05-06 13:28                     ` Diego Olivier Fernandez Pons
2003-05-13 11:35                   ` [Caml-list] Data Structure Libraries (was: Two types of efficiency) Oleg Trott
2003-05-04  7:55           ` [Caml-list] Efficiency of 'a list Ville-Pertti Keinonen
2003-05-04 10:56             ` Neel Krishnaswami
2003-05-04 12:56               ` Eray Ozkural
2003-05-04 13:35                 ` Falk Hueffner
2003-05-04 12:38           ` Eray Ozkural
2003-05-04  8:07         ` Ville-Pertti Keinonen
2003-05-04 15:54           ` Ed L Cashin
2003-05-05 23:52           ` Garry Hodgson
2003-05-03 20:03   ` Eray Ozkural
2003-05-03 21:13 ` Lauri Alanko
2003-05-03 22:03   ` Eray Ozkural

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=3EB6452E.8030100@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=andrieu@ijm.jussieu.fr \
    --cc=caml-list@inria.fr \
    /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).