Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: John Skaller <skaller@ozemail.com.au>
To: caml-list@inria.fr
Subject: [Caml-list] Fun with fixpoints
Date: Wed, 25 Jun 2003 16:57:22 +1000	[thread overview]
Message-ID: <3EF947D2.2050500@ozemail.com.au> (raw)

type 't t0' = [`A of 't]
type 't t1' = [`B of 't]
type 't t' = [ 't t0' | 't t1'] (* unify *)

type t0 = 't t0' as 't  (* fix *)
type t1 = 't t1' as 't  (* fix *)

type t = 't t' as 't  (* fix *)
type tt = [t0 | t1] (* unify *)

Ocaml replies with ....

type t = 'a t' as 'a
type tt = [ `A of 'a t0' as 'a | `B of 'b t1' as 'b ]


   param pair ----- fix ----> pair
     |                         |
    unify                    unify
     |                         |
     |                       coerce
     |                         |
     V                         V
    param type --- fix ----> type

This example shows how expressive polymorphic
variants really are. In particular, they can not
only union types, they can union type functors
(parameterised types).

Ocaml even knows the subtype relations:

let f(x:tt) = (x:tt:>t)
let f(x:t1):t = (x:t1:>t)
let f(x:t1):tt = (x:t1:>tt

but you have to use a double coercion to tell it.

-- 
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-06-25  6:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3EF947D2.2050500@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --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