caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Why type inference fails in this code
@ 2009-10-09  5:25 rouanvd
  2009-10-09  6:54 ` [Caml-list] " Vincent Aravantinos
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: rouanvd @ 2009-10-09  5:25 UTC (permalink / raw)
  To: caml-list

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 don’t 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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-10-09 10:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-09  5:25 Why type inference fails in this code rouanvd
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

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