caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Type aliases
@ 2002-11-28 18:01 Martin Jambon
  2002-11-28 18:51 ` Alain Frisch
  2002-11-28 18:55 ` Alessandro Baretta
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Jambon @ 2002-11-28 18:01 UTC (permalink / raw)
  To: caml-list

Hi,

I would like to have the following properties:

1) Define type aliases:

     type year = int
     and month = int

2) Don't hide their representation and derive the primitives from the
   original type:

     # let next_year = current_year + 1 ;;
     val next_year : year = 2003

   (+) and 1 would be silently converted to types using year instead of
   int.


3) Prohibit the mixing of different types that do not derive from each
   other, without an explicit cast:

     let my_mistake = year + month   (* Type error! *)

   where year has type year and month has type month.
   But this could be valid:

     let some_int = (year :> int) * 13 + month


Basically, I would like to minimize the risk of error when I manipulate
simple datatypes like numerical parameters or int/string identifiers.


Thanks for any suggestion!

Martin

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-29 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-28 18:01 [Caml-list] Type aliases Martin Jambon
2002-11-28 18:51 ` Alain Frisch
2002-11-29 14:03   ` Martin Jambon
2002-11-28 18:55 ` Alessandro Baretta

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