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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 83D207EDC2 for ; Wed, 21 Nov 2012 04:05:47 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of berenger@riken.jp) identity=pra; client-ip=134.160.33.175; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of berenger@riken.jp designates 134.160.33.175 as permitted sender) identity=mailfrom; client-ip=134.160.33.175; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="berenger@riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of postmaster@postman.riken.jp designates 134.160.33.175 as permitted sender) identity=helo; client-ip=134.160.33.175; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="berenger@riken.jp"; x-sender="postmaster@postman.riken.jp"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQBALZErFCGoCGvhWdsb2JhbABEwmwOAQEBCgsLBRYngh4BAQQBOEAGCwsYCRYPCQMCAQIBDzYTBgIBAReHYAMJBrVVDYlUi0tpgTuDJwOIWotPgVWBHIRPhUeIDQ X-IronPort-AV: E=Sophos;i="4.83,290,1352070000"; d="scan'208";a="163215532" Received: from postman3.riken.jp (HELO postman.riken.jp) ([134.160.33.175]) by mail4-smtp-sop.national.inria.fr with ESMTP; 21 Nov 2012 04:05:15 +0100 Received: from postman.riken.jp (postman3.riken.jp [127.0.0.1]) by postman.riken.jp (Postfix) with SMTP id E509238380B7 for ; Wed, 21 Nov 2012 12:05:11 +0900 (JST) Received: from [172.27.98.103] (rikad98.riken.jp [134.160.214.98]) by postman.riken.jp (Postfix) with ESMTPA id BB9D838201A2 for ; Wed, 21 Nov 2012 12:05:10 +0900 (JST) Message-ID: <50AC44E6.1070702@riken.jp> Date: Wed, 21 Nov 2012 12:05:10 +0900 From: Francois Berenger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.6.0.2009776, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.11.21.25415 Subject: Re: [Caml-list] How to add a hook to Stream.junk? On 11/21/2012 10:35 AM, Wojciech Meyer wrote: > bob zhang writes: > >> Hi List, >> Does anyone know any trick to add a hook to Stream.junk, I have >> tried different ways, but did not find any solution, yet >> I want to trigger an action each time when I junk a token from the >> stream. (copy the whole file from stdlib is fine, but I don't >> know how to make the type checker happy :-() >> -- >> Regards >> -- Bob > > You can parametrise the Stream.t type with your desired type and the > hook. > > Then you can substitute type using destructive substitution of a type: > > module Stream : module type of Stream with type 'elt t := ('hook, 'elt) > CustomStream.t = Stream > > Finally you can implement your own CustomStream.junk function that > operates on the parametrised type and include the CustomStream module. Why the need for module type of and all? Why not simply: module MyStream = struct include Stream let junk = failwith "put your code here" end;; Which I can read as "MyStream is a Stream where I redefined the junk operation". > This should work, but I've not tested or compiled it. > -- > Wojciech Meyer > http://danmey.org >