caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] let rec and polymorphic functions
Date: Wed, 27 Jun 2007 10:05:10 +0100	[thread overview]
Message-ID: <200706271005.10837.jon@ffconsultancy.com> (raw)
In-Reply-To: <000e01c7b896$d3372440$6a7ba8c0@treble>


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

>   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.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e


  reply	other threads:[~2007-06-27  9:11 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 ` Jon Harrop [this message]
2007-06-27 10:14   ` [Caml-list] " Arnaud Spiwack
     [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=200706271005.10837.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.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).