caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Warren Harris <warren@liveops.com>
To: "Julien Moutinho - julien.moutinho@gmail.com"
	<+caml+warren+b1373cd4e6.julien.moutinho#gmail.com@spamgourmet.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] question about polymorphic methods (caml: to exclusive)
Date: Mon, 24 Sep 2007 16:45:57 -0700	[thread overview]
Message-ID: <46F84C35.9030903@liveops.com> (raw)
In-Reply-To: <20070924122341.GB4663@localhost>

[-- Attachment #1: Type: text/plain, Size: 2414 bytes --]

Julien, Thanks for your suggestion. I realize that I can paper over the 
problem in various ways, but I was hoping for a more type-theoretic 
approach to solving the problem of needing an implementation-specific 
but otherwise abstract type parameter in printf's signature. If I could 
declare 'b as a function of the particular implementation in question, 
that might solve it, but I'm not sure how to express this.

Warren


Julien Moutinho - julien.moutinho@gmail.com wrote:
> On Sun, Sep 23, 2007 at 07:11:21PM -0700, Warren Harris wrote:
>   
>> I have a simple output stream class that abstracts over out_channels and 
>> buffers. I would like to add a printf method that takes a format directive, 
>> and calls the appropriate Printf function.
>> [...]
>> This type parameter propagates through numerous places in my code,
>> in some cases requiring other methods to become polymorphic.
>>     
>
> Consider using the class below instead of out_stream directly:
>
> class my'out_stream och buf =
>   object
>     val buffer = new out_stream_of_buffer buf
>     method buffer = buffer
>     val outchan = new out_stream_of_channel och
>     method outchan = outchan
>   end
>
> Or this one, depending on how you get your buf and och:
>
> class my'out_stream'opt
>   ?och ?buf () =
>   object (self)
>     val mutable buffer = None
>     method init_buffer buf =
>         buffer <- Some (new out_stream_of_buffer buf)
>     initializer
>         match buf with None -> ()
>         | Some buf -> self#init_buffer buf
>     method buffer =
>         match buffer with
>         | Some o -> o
>         | None -> failwith "MyStream.my'out_stream'opt#buf: no buffer provided"
>     
>     val mutable outchan = None
>     method init_outchan och =
>         outchan <- Some (new out_stream_of_channel och)
>     initializer
>         match och with None -> ()
>         | Some och -> self#init_outchan och
>     method outchan =
>         match outchan with
>         | Some o -> o
>         | None -> failwith "MyStream.my'out_stream'opt#och: no channel provided"
>   end
>
> HTH,
>   Julien.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>   

[-- Attachment #2: Type: text/html, Size: 3170 bytes --]

  reply	other threads:[~2007-09-24 23:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-24  2:11 question about polymorphic methods Warren Harris
2007-09-24 12:23 ` [Caml-list] " Julien Moutinho
2007-09-24 23:45   ` Warren Harris [this message]
2007-09-25  1:25     ` [Caml-list] question about polymorphic methods (caml: to exclusive) Till Varoquaux

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=46F84C35.9030903@liveops.com \
    --to=warren@liveops.com \
    --cc=+caml+warren+b1373cd4e6.julien.moutinho#gmail.com@spamgourmet.com \
    --cc=caml-list@yquem.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).