From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 393DB7EE5B for ; Fri, 16 May 2014 23:41:26 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of pjfrey@sympatico.ca) identity=pra; client-ip=65.55.111.100; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of pjfrey@sympatico.ca designates 65.55.111.100 as permitted sender) identity=mailfrom; client-ip=65.55.111.100; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@blu0-omc2-s25.blu0.hotmail.com) identity=helo; client-ip=65.55.111.100; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="postmaster@blu0-omc2-s25.blu0.hotmail.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am0BAAiFdlNBN29klGdsb2JhbABZg1WDQcEXATZgFg4BAQEBBwsLCRIqgiUBAQUjBFIQCxgCAiYCAlcGDgIDG4gmDa0ypFAXgSqMchAjB4J1NoEVAQOTOIddhRMakAJRAQ X-IPAS-Result: Am0BAAiFdlNBN29klGdsb2JhbABZg1WDQcEXATZgFg4BAQEBBwsLCRIqgiUBAQUjBFIQCxgCAiYCAlcGDgIDG4gmDa0ypFAXgSqMchAjB4J1NoEVAQOTOIddhRMakAJRAQ X-IronPort-AV: E=Sophos;i="4.97,1069,1389740400"; d="scan'208";a="62213610" Received: from blu0-omc2-s25.blu0.hotmail.com ([65.55.111.100]) by mail3-smtp-sop.national.inria.fr with ESMTP; 16 May 2014 23:41:25 +0200 Received: from BLU0-SMTP74 ([65.55.111.71]) by blu0-omc2-s25.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 16 May 2014 14:41:23 -0700 X-TMN: [nqxeHGYhLxwP+yK4dkoGuXyuSRtno/ka] X-Originating-Email: [pjfrey@sympatico.ca] Message-ID: Received: from [192.168.2.11] ([70.27.0.49]) by BLU0-SMTP74.phx.gbl over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 16 May 2014 14:41:21 -0700 From: Peter Frey To: Jeremy Yallop CC: Caml List Date: Fri, 16 May 2014 17:41:20 -0400 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-OriginalArrivalTime: 16 May 2014 21:41:22.0074 (UTC) FILETIME=[9441F7A0:01CF714F] Subject: Re: [Caml-list] Unifying buildt-in types with polymorphic types On Thu, 2014-05-15 at 21:28 +0100, Jeremy Yallop wrote: > 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. > This helped a lot, thank you. (Typing is hard; I have been programming since 1963 and always had a clear idea what I was doing, because previous languages translated statements into code; Assemblers (many) Cobol Fortran Snobol Prolog Pascal Cs ... Now the type checker translates types into types... perhaps I am getting to old...) thanks again Peter