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.4 required=5.0 tests=AWL,NO_REAL_NAME autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D32D7BC6B for ; Sat, 4 Aug 2007 20:51:42 +0200 (CEST) Received: from triton.rz.uni-saarland.de (triton.rz.uni-saarland.de [134.96.7.25]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l74Ipg0T027425 for ; Sat, 4 Aug 2007 20:51:42 +0200 Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by triton.rz.uni-saarland.de (8.12.11.20060614/8.12.10) with ESMTP id l74IpeUp24378071 for ; Sat, 4 Aug 2007 20:51:40 +0200 (CEST) Received: from mail.ps.uni-sb.de (james.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.14.1/2007062800) with ESMTP id l74IpdKS000120 for ; Sat, 4 Aug 2007 20:51:39 +0200 (CEST) Received: from localhost ([127.0.0.1] helo=www.ps.uni-sb.de ident=www-data) by mail.ps.uni-sb.de with esmtp (Exim 4.63) (envelope-from ) id 1IHOix-0005Le-G9 for caml-list@inria.fr; Sat, 04 Aug 2007 20:51:39 +0200 Received: from 84.165.140.254 (SquirrelMail authenticated user rossberg) by www.ps.uni-sb.de with HTTP; Sat, 4 Aug 2007 20:51:39 +0200 (CEST) Message-ID: <64963.84.165.140.254.1186253499.squirrel@www.ps.uni-sb.de> In-Reply-To: <46B4A343.5030900@lix.polytechnique.fr> References: <46B4A343.5030900@lix.polytechnique.fr> Date: Sat, 4 Aug 2007 20:51:39 +0200 (CEST) Subject: Re: [Caml-list] Instanciating functor types with extra parameters From: rossberg@ps.uni-sb.de To: "Caml List" User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: rossberg@ps.uni-sb.de X-SA-Exim-Scanned: No (on mail.ps.uni-sb.de); SAEximRunCond expanded to false X-DCC-CTc-dcc2-Metrics: itelist X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.5.1 (triton.rz.uni-saarland.de [134.96.7.25]); Sat, 04 Aug 2007 20:51:40 +0200 (CEST) X-AntiVirus: checked by AntiVir MailGate (version: 2.1.2-14; AVE: 7.4.0.57; VDF: 6.39.0.213; host: AntiVir0) X-Miltered: at concorde with ID 46B4CABE.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; functor:01 rossberg:01 lix:01 functor:01 orderedtype:01 sig:01 val:01 orderedtype:01 struct:01 ocaml:01 sig:01 val:01 struct:01 innocent:98 arnaud:01 From: "Arnaud Spiwack" > > When I have a functor type, like for example (not too innocent > I'm afraid) : > > module type OrderedType = > sig > type t > val compare : t -> t -> int > end > > Something that naive intuition would allow you to do is something like : > > module GenOrder : OrderedType = > struct > type t = 'a > let compare = compare > end > > Though this is more or less nonsense. And is not currently possible > under OCaml type system. > > My point is that I know absolutely no way of doing such a thing. If you have control over the functor type then you can do this: module type OrderedPolyType = sig type 'a t val compare : 'a t -> 'a t -> int end module GenOrder : OrdererPolyType = struct type 'a t = 'a let compare = compare end module InvIntOrder : OrdererPolyType = struct type 'a t = int let compare x y = compare y x end Not a general solution, but one that's often good enough. - Andreas