From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0A76EBC57 for ; Wed, 17 Nov 2010 05:10:15 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtAAAPvj4kxKfVK0kGdsb2JhbACDSJ5yCBUBAQEBCQkMBxEDH6Y+iSaCVIUCiQcBAQMFgR2DNnMEhFqFfokq X-IronPort-AV: E=Sophos;i="4.59,209,1288566000"; d="scan'208";a="79267882" Received: from mail-wy0-f180.google.com ([74.125.82.180]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Nov 2010 05:10:14 +0100 Received: by wya21 with SMTP id 21so1536019wya.39 for ; Tue, 16 Nov 2010 20:10:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=ykpUEG01sCaiFapbYKB4CXXOWiNHL0o7wNcja1c3Nlc=; b=CEVwbPbv7ccOvQNO5CyUofdwBmPRka0sO5hPOvB9lJp0O13gU95XKqkOPMRuQH4deA hcOdOktC2vxOxWOw4aQR46b+VYIga1ajftUE7PSk+2Re32fa42JTs9Wk3mJX0Q7AgOMT slxED3rX5nddii8MKvvDV/C7J4fVXhd9juMYU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=gKSYv8T3PCWZpR8Qa0Qseq7GwFiiiVQF6dAe/UBHKu6An0i1kf6nF0qV7j3SKCKIxV +7yzmRG/7Mi/NIVk6gT4E+XkMP3bGVY37EY0vfWOQQ8NgRn6phfzQ0ZIsqZEupXqAJaR cWGDgeERwaOIEKypUUYfsaBhxJVzK4PPJlels= MIME-Version: 1.0 Received: by 10.216.38.84 with SMTP id z62mr1138803wea.70.1289967014110; Tue, 16 Nov 2010 20:10:14 -0800 (PST) Sender: till.varoquaux@gmail.com Received: by 10.216.79.70 with HTTP; Tue, 16 Nov 2010 20:10:14 -0800 (PST) Date: Tue, 16 Nov 2010 23:10:14 -0500 X-Google-Sender-Auth: -98iqfiKYOShp3sk_bCwqTQH9mY Message-ID: Subject: Lightweight way to extend existing module. Almost there? From: Till Varoquaux To: Caml Mailing List Content-Type: text/plain; charset=UTF-8 X-Spam: no; 0.00; ocaml:01 stdlabels:01 sig:01 stdlabels:01 val:01 bool:01 struct:01 stringlabels:01 bool:01 listlabels:01 arraylabels:01 needle:98 needle:98 pps:01 jussieu:01 With the improvements to the module system in ocaml 3.12 extending a signature just got much much lighter. Suppose I want the signature of the module which in every respects is like StdLabels excepted that the String module has an extra "is_prefix_of" I can write: module String : sig include module type of StdLabels.String val is_prefix_of : string -> string -> bool end include module type of StdLabels with module String := String I know of no way to extend the implementation in a similarly concise way (for which the length of the solution does not depend on the number of top level items in StdLabels). Have I overlooked anything obvious? Till P.S.: FYI existing solution for the implementation: module String = struct include StringLabels let is_prefix_of (needle:string) (haystack:string) : bool = let len = length needle in len <= length haystack && (sub haystack ~pos:0 ~len = needle) end (* Haven't quite found out how to include a module hiding another one... *) module List = ListLabels module Array = ArrayLabels