From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 16B4EBC69 for ; Wed, 14 Nov 2007 17:20:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FADqvOkdCm3xr/2dsb2JhbACCdCk X-IronPort-AV: E=Sophos;i="4.21,417,1188770400"; d="scan'208,217";a="4457902" Received: from www.janestcapital.com (HELO smtp.janestcapital.com) ([66.155.124.107]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Nov 2007 17:20:08 +0100 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id A03706A4; Wed, 14 Nov 2007 11:20:07 -0500 Message-ID: <473B2037.6040704@janestcapital.com> Date: Wed, 14 Nov 2007 11:20:07 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Edgar Friendly Cc: Yaron Minsky , caml-list Subject: Re: [Caml-list] Compiler feature - useful or not? References: <473A363F.2080301@gmail.com> <891bd3390711131608g48b584a4n6b0ccab95d7de3f3@mail.gmail.com> <473B1DC4.8030307@gmail.com> In-Reply-To: <473B1DC4.8030307@gmail.com> Content-Type: multipart/alternative; boundary="------------060605040001030004000508" X-Spam: no; 0.00; compiler:01 yaron:01 minsky:01 sig:01 val:01 val:01 implements:01 compiler:01 syntax:01 ocamlc:01 ocaml:01 inlining:01 yaron:01 minsky:01 sig:01 This is a multi-part message in MIME format. --------------060605040001030004000508 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Edgar Friendly wrote: >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. > > Actually, Ocaml is pretty good at cross-module inlining, so that normally the function call is optimized out, and the whole conversion becomes a no-op. Or, at least, such has been my experience. Brian --------------060605040001030004000508 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Edgar Friendly wrote:
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.
  

Actually, Ocaml is pretty good at cross-module inlining, so that normally the function call is optimized out, and the whole conversion becomes a no-op.  Or, at least, such has been my experience.

Brian

--------------060605040001030004000508--