From: rouanvd@softwarerealisations.com
To: caml-list@yquem.inria.fr
Subject: Why type inference fails in this code
Date: Fri, 9 Oct 2009 07:25:41 +0200 (SAST) [thread overview]
Message-ID: <53322.41.177.16.252.1255065941.squirrel@41.177.16.252> (raw)
Hi everyone
I am trying to decide what language to use to write a compiler for my own
programming language.
I am leaning towards OCaml, but I dont want the type system or debugging
tools to be a problem.
I found this code snippet in a post and was wondering why the type
inference messes up with
The following code:
======================================================
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 have done the same thing in Haskell and it correctly infers the type of
foo.
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.
Regards
Rouan.
next reply other threads:[~2009-10-09 6:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-09 5:25 rouanvd [this message]
2009-10-09 6:54 ` [Caml-list] " Vincent Aravantinos
2009-10-09 7:09 ` 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=53322.41.177.16.252.1255065941.squirrel@41.177.16.252 \
--to=rouanvd@softwarerealisations.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