Browse thread
Compiler feature - useful or not?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Edgar Friendly <thelema314@g...> |
| Subject: | Re: [Caml-list] Compiler feature - useful or not? |
Yaron Minsky wrote: > module type Abs_int : sig > type t > val to_int : t -> int > val of_int : int <- t > end > > And then you write concrete module Int that implements this signature. You > can then write: > > module Row : Abs_int = Int > module Col : Abs_int = Int > This approximates my idea of "optimal" well enough that I'll rewrite some of my old code to use it. It loses some opportunities for compiler optimization, but otherwise seems perfect. No repetitive boilerplate to write over and over, no unnecessary boxing, efficient conversion to the base type (well, it still requires a function call to find out that nothing needs to change, and maybe there's a shallow copy created in this process), easy on the eyes/fingers syntax for conversion and declaration and a readable type name for ocamlc to report when things go wrong. Thanks for sharing this gem. Any chance it can be added to a/the FAQ? E.