Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Martin Jambon <m.jambon@i...>
Subject: [Caml-list] Type aliases
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