From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C5A527EE5B for ; Thu, 15 May 2014 22:28:27 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.212.180; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yallop@gmail.com designates 209.85.212.180 as permitted sender) identity=mailfrom; client-ip=209.85.212.180; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f180.google.com) identity=helo; client-ip=209.85.212.180; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-wi0-f180.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al8BAKgidVPRVdS0lGdsb2JhbABZg1VYgmjCNgGBCggWDgEBAQEHCwsJEiqCJQEBBSMEGQEbHQEDDAYFCwMKAgImAgIiAREBBQEcBhMbiBEBAxENoEOMEVGDDZoXChknDWSFMxEBBQyBHo0kB4J1gUsEmVGBPY9mGCmEZzwwAQ X-IPAS-Result: Al8BAKgidVPRVdS0lGdsb2JhbABZg1VYgmjCNgGBCggWDgEBAQEHCwsJEiqCJQEBBSMEGQEbHQEDDAYFCwMKAgImAgIiAREBBQEcBhMbiBEBAxENoEOMEVGDDZoXChknDWSFMxEBBQyBHo0kB4J1gUsEmVGBPY9mGCmEZzwwAQ X-IronPort-AV: E=Sophos;i="4.97,1061,1389740400"; d="scan'208";a="73941628" Received: from mail-wi0-f180.google.com ([209.85.212.180]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 15 May 2014 22:28:27 +0200 Received: by mail-wi0-f180.google.com with SMTP id hi2so4855282wib.13 for ; Thu, 15 May 2014 13:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=TpFUr8e2Y1QKZA74BTMIu5UWcczdBfVP3sLbDLgYEZU=; b=L+X5ZHrjiZfqzQCMvfvmULpiuKgz7/MIw2orCCznJzR904cD6W5X8m3knTp1nIb8Ao RQwyj485iQCup26HXZAHoI1Icxfl6Ks9joVTwMsplmaFpvG93Ny2WZsma5LcTWd1HXPW TSPZB7/mBIoboZJlVurZqop6VzoSFzDsAi7piUZa2nhipI2G/s0TC6fgsxSuibbVdadn SXj5PQoc5LtSuRO8Gt6WeiKa5xklWNaeezsfZYsTu4BA0xckN/EAuwd9NxKgOuzKaf2q jpMqeU04SwHyyHH3SuEmt9lt5z40apfJ24trA+SkZE3V35mGKYiwH5s3FuJkiYIbjwm4 gsQQ== MIME-Version: 1.0 X-Received: by 10.180.36.35 with SMTP id n3mr20606681wij.23.1400185706959; Thu, 15 May 2014 13:28:26 -0700 (PDT) Received: by 10.217.5.65 with HTTP; Thu, 15 May 2014 13:28:26 -0700 (PDT) In-Reply-To: References: Date: Thu, 15 May 2014 21:28:26 +0100 Message-ID: From: Jeremy Yallop To: Peter Frey Cc: Caml List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Unifying buildt-in types with polymorphic types On 15 May 2014 20:24, Peter Frey wrote: > I need all streams to have the same signature 'StreamOps'. It's not possible with the current definition of StreamOps. The difficulty is that the stream type and the element type vary non-uniformly in your various stream implementations: StmLzy defines streams of type 'a t = Cons of 'a * 'a t Lazy.t with elements of 'a StmAry defines streams of type 'a t = int * 'a cursor with elements of 'a StmStr defines streams of type 'a t = int * 'a cursor with elements of char but the signature leaves only the stream type 'a t unspecified, providing no way for the element type to vary in the implementation. One solution is to change the StreamOps signature to include both the element type and the stream type. Once you've added an element type to the signature there's no need to parameterize the stream type: module type StreamOps = sig type elt (* the element type *) type t (* the stream type *) val head : t -> elt end The implementations of StreamOps then become functors over the element type. This is the approach used in the standard library to define maps and sets (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Set.Make.html). For example, you might define LazyStream as follows module LazyStream (E : sig type elt end) : StreamOps with type elt = E.elt = struct type elt = E.elt type t = Cons of elt * t Lazy.t let head (Cons (h, _)) = h end The element type of StmStr doesn't vary, so there's no need to make it a functor: module StmStr : StreamOps with type elt = char = struct type elt = char type cursor = { ofs: int; lim: int; data: string } type t = int * cursor let get s i = String.get s.data i let head (i, s) = get s i end I hope that helps, Jeremy.