caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Vincent Aravantinos <vincent.aravantinos@gmail.com>
To: rouanvd@softwarerealisations.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Why type inference fails in this code
Date: Fri, 9 Oct 2009 08:54:58 +0200	[thread overview]
Message-ID: <668FA99E-41F3-4BEF-9F55-2C45DEE6CAD3@gmail.com> (raw)
In-Reply-To: <53322.41.177.16.252.1255065941.squirrel@41.177.16.252>


Le 9 oct. 09 à 07:25, rouanvd@softwarerealisations.com a écrit :

> ======================================================
> type t = MyInt of int | MyFloat of float | MyString of string ;;
>
> let foo printerf = function
>  | MyInt i -> printerf string_of_int i
>  | MyFloat x -> printerf string_of_float x
>  | MyString s -> printerf (fun x -> x) s
> ;;
> ======================================================


> I read that there are lots of workarounds for the above code  
> snippet, but
> I would like to
> Know why this code fails and what is the best workaround for this  
> type of
> code.

You might find some answers here:
http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#arguments_polymorphes
Though this won't clearly tell you "why", and I sadly don't know the  
answer.

 From my experience the type system limitations are not so big  
hindrance in practice,
you may have to work a bit to get what you want fit in the type system,
but I've never found a thing that wouldn't work at all.

BTW:

> I have done the same thing in Haskell and it correctly infers the  
> type of
> foo.

It doesn't work for me with ghc 6.10.3.
I mean, unless you provided the Haskell compiler with some type  
annotations the same error occurs.
But I am not a haskell expert so I may be wrong.

V.

  reply	other threads:[~2009-10-09  6:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09  5:25 rouanvd
2009-10-09  6:54 ` Vincent Aravantinos [this message]
2009-10-09  7:09 ` [Caml-list] " Gabriel Kerneis
2009-10-09  8:22   ` Virgile Prevosto
2009-10-09  8:41     ` Gabriel Kerneis
2009-10-09  8:59       ` Gabriel Kerneis
2009-10-09 10:22 ` Jeremy Yallop

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=668FA99E-41F3-4BEF-9F55-2C45DEE6CAD3@gmail.com \
    --to=vincent.aravantinos@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=rouanvd@softwarerealisations.com \
    /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).