Browse thread
Why type inference fails in this code
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2009-10-09 (06:16) |
From: | rouanvd@s... |
Subject: | Why type inference fails in this code |
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.