caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Francois Berenger <berenger@riken.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] How to add a hook to Stream.junk?
Date: Wed, 21 Nov 2012 12:05:10 +0900	[thread overview]
Message-ID: <50AC44E6.1070702@riken.jp> (raw)
In-Reply-To: <wf8v9vwxf0.fsf@gmail.com>

On 11/21/2012 10:35 AM, Wojciech Meyer wrote:
> bob zhang <bobzhang1988@gmail.com> 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
>


  parent reply	other threads:[~2012-11-21  3:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21  1:07 bob zhang
2012-11-21  1:35 ` Wojciech Meyer
2012-11-21  2:58   ` [Caml-list] " bobzhang
2012-11-21  3:37     ` Wojciech Meyer
2012-11-21  3:05   ` Francois Berenger [this message]
2012-11-21  3:34     ` [Caml-list] " Wojciech Meyer
2012-11-21  3:39       ` [Caml-list] " bobzhang
2012-11-21  3:45         ` Wojciech Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50AC44E6.1070702@riken.jp \
    --to=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).