Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "andrew cooke" <andrew@acooke.org>
To: "ocaml list" <caml-list@inria.fr>
Subject: [Caml-list] Newbie: Aliases for polymorphic variants
Date: Sat, 28 Feb 2004 09:44:16 -0300 (CLST)	[thread overview]
Message-ID: <56138.139.229.3.218.1077972256.squirrel@localhost> (raw)


Hi,

I've just been looking at polymorphic variants.  They seem quite neat. 
However, I have some questions....

1 - It seems to me that they could be particularly useful for solving
those nasty practical problems that occur way down the line with old
systems where you want to combine previously separate features in some
way.

However, to do that, it seems like all code has to use polymorphic
variants from the start.  Is that right?

That seems OK, except that they seem to make for a lot more typing.  Is
there a syntax for defining something like type aliases?  I'm looking for
something like:

alias 'a Node = `Node int * 'a `Node * 'a `Node

so that I can type just 'a Node instead of `Node int * 'a `Node * 'a `Node
everywhere

2 - Alternatively, say I have

type 'a beginWithF = [Foo of 'a | Flob of int * 'a]
type 'a beginWithG = [Goo of 'a]

is there a syntax something like:

type 'a beginWithFOrG = ['a beginWithF | 'a beginWithG]

or do I have to explicitly list all the separate constructors?

3 - Am I right in thinking that fucntions cannot be defined with pattern
matching to the left of "=" in OCaml?  (ie not like Haskell)  If this were
possible then I think you'd have ad-hoc polymorphism for free because you
could have:

fun sum (`Integer i) (`Integer j) = `Integer (i + j)
fun sum (`Real x) (`Real y) = `Real (x +. y)

Does that make sense?

4 - Taking (3) further, couldn't you give all types an implicit
polymorphic variant constructor?  Then you could have types like [int |
float] directly.  Does that make sense?

Thanks,
Andrew

-- 
  __ _ __ ___  ___| |_____   work web site: http://www.ctio.noao.edu/~andrew
 / _` / _/ _ \/ _ \ / / -_)  personal web site: http://www.acooke.org/andrew
 \__,_\__\___/\___/_\_\___|  personal gallery: http://www.acooke.org/pancito

-------------------
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:[~2004-02-28 12:44 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=56138.139.229.3.218.1077972256.squirrel@localhost \
    --to=andrew@acooke.org \
    --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