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
Compiler feature - useful or not?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-14 (16:09)
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

Thanks for sharing this gem.  Any chance it can be added to a/the FAQ?