From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 279747EDC2 for ; Wed, 21 Nov 2012 02:35:12 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of wojciech.meyer@googlemail.com) identity=pra; client-ip=74.125.82.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="wojciech.meyer@googlemail.com"; x-sender="wojciech.meyer@googlemail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of wojciech.meyer@googlemail.com designates 74.125.82.182 as permitted sender) identity=mailfrom; client-ip=74.125.82.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="wojciech.meyer@googlemail.com"; x-sender="wojciech.meyer@googlemail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-we0-f182.google.com) identity=helo; client-ip=74.125.82.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="wojciech.meyer@googlemail.com"; x-sender="postmaster@mail-we0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0BAHYurFBKfVK2kGdsb2JhbABEhVm8cggWDgEBAQEJCQ0HFAQjgh4BAQQBQAE4AQMBCwYFCxYlDwEEDRMBBQEiExuHXwEDCQYEoFGPKYEHhAQKQA2JTgEFDIs/hUsDlCmBVYEcihaDLz+EAw0 X-IronPort-AV: E=Sophos;i="4.83,290,1352070000"; d="scan'208";a="182428169" Received: from mail-we0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Nov 2012 02:35:11 +0100 Received: by mail-we0-f182.google.com with SMTP id u54so2437879wey.27 for ; Tue, 20 Nov 2012 17:35:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=UldjLuSw1CusRnh4LCbUQ35MP9Pk8IhcoVNSsGu9/WM=; b=tZgNJWrK0TobxVbiRPTrUsgJHrAJbgq+mzVMpiGvf7i4KgExCwqvFarpHeKxEcUNkm XnXHNPXBv1cUezkEp0X6In/lTbtvMgS3YMbplq5WT74PxtHPHnLGRPezPPLtELSWbGsP v6OfIilBNTUetztO8C7Kpr9PscbuLU6WymozpWXB5NYdIV+0h2qVhH96S1dXekDkD+ME 8svJZxRrEYUnBbPF2K0aZIfSmaoWgQ6EcjNlMVgPv/YVhoiGbVy5vw+gmr9nMfVEw0ug 5H8A5tUtDXcxlEHkTcjqoxdaQZp3bgN3PQLLHClvEXM1VwIZwtMtI7rct07GbOHDWLAu qPeA== Received: by 10.216.204.213 with SMTP id h63mr1584324weo.43.1353461711388; Tue, 20 Nov 2012 17:35:11 -0800 (PST) Received: from spec-desktop.danmey.org (cpc1-cmbg12-0-0-cust201.5-4.cable.virginmedia.com. [86.9.116.202]) by mx.google.com with ESMTPS id gz3sm20038594wib.2.2012.11.20.17.35.09 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Nov 2012 17:35:10 -0800 (PST) From: Wojciech Meyer To: bob zhang Cc: Caml List References: Date: Wed, 21 Nov 2012 01:35:15 +0000 In-Reply-To: (bob zhang's message of "Tue, 20 Nov 2012 20:07:53 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] How to add a hook to Stream.junk? 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. This should work, but I've not tested or compiled it. -- Wojciech Meyer http://danmey.org