caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Arnaud Spiwack <aspiwack@lix.polytechnique.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] let rec and polymorphic functions
Date: Wed, 27 Jun 2007 12:14:20 +0200	[thread overview]
Message-ID: <4682387C.5070600@lix.polytechnique.fr> (raw)
In-Reply-To: <200706271005.10837.jon@ffconsultancy.com>

Jon Harrop a écrit :
> There are many problems with this. Google for ad-hoc polymorphism, polymorphic 
> recursion and generic printing.
>
> On Wednesday 27 June 2007 09:40:31 David Allsopp wrote:
>   
>>   out "TEST";
>>     
>
> val out : string -> unit
>   
Actually it seems to infer properly "out : (unit, out_channel, unit) 
format -> unit". So the magic is pulled here (which surprises me a lot, 
but well). The problem seems more related to the fact that mutual 
recursive function are monomorphic.
>   
>>   out "%d" 0;
>>     
>
> val out : format -> int -> unit
>
> As printf is ad-hoc polymorphic, you must supply the format specifier 
> immediately and OCaml will generate a custom printer for you. OCaml does not 
> use run-time types so you cannot have a generic print function: you must 
> specific print functions for each of your (possibly higher-order) types.
>
> Also, recursive calls ossify the function to a monomorphic type, so you cannot 
> do polymorphic recursion in OCaml. There are workaround using recursive 
> modules or objects but I don't think this is what you want here.
>
>   


  reply	other threads:[~2007-06-27 10:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-27  8:40 David Allsopp
2007-06-27  9:05 ` [Caml-list] " Jon Harrop
2007-06-27 10:14   ` Arnaud Spiwack [this message]
     [not found] <20070627100004.9E0DABC73@yquem.inria.fr>
2007-06-27 10:24 ` David Allsopp
2007-06-27 11:12   ` Jeremy Yallop
2007-06-27 11:29     ` David Allsopp
2007-06-27 12:00     ` Virgile Prevosto
2007-06-27 13:00       ` Jeremy Yallop
2007-06-27 13:12   ` Jon Harrop

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=4682387C.5070600@lix.polytechnique.fr \
    --to=aspiwack@lix.polytechnique.fr \
    --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).