r***@softwarerealisations.com
2009-10-09 06:16:22 UTC
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.
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
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.
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs