caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Polymorphic variants for basic types?
@ 2000-01-15 19:06 Markus Mottl
  0 siblings, 0 replies; only message in thread
From: Markus Mottl @ 2000-01-15 19:06 UTC (permalink / raw)
  To: OCAML

Hello,

this idea has probably already been considered: what do you think about
translating basic values prefixed by "`" to polymorphic variants
automatically during compilation?

E.g.

  match foo with                        match foo with
  | `"Some string" -> ...        to     | `String "Some string" -> ...
  | `42 ->                              | `Int 42 -> ... 
  | `[x; y; z] ->                       | `List [x; y; z] -> ...
  ...
  
As far as I can see, this would not be a difficult thing to do, because it
only seems to require syntactic information. Probably even the preprocessor
could be used for this.

Some nice things would be possible then, like the one above or conveniently
writing down complex datastructures (e.g. trees with arbitrary numbers of
subnodes):

  let tree = `[ `3; `[`4; `5]; `[ `[`6] ] ] in ...

which is probably much easier to write than:

  let tree =
    `List [ `Int 3;
            `List [`Int 4; `Int 5];
            `List [ `List [`Int 6] ] ] in ...

Anyway, this is just a small feature suggestion - I am sure there are more
important language properties at the moment to reason about.

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-01-16 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-15 19:06 Polymorphic variants for basic types? Markus Mottl

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).