English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Type aliases
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-28 (18:01)
From: Martin Jambon <m.jambon@i...>
Subject: [Caml-list] Type aliases

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

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!


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