From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 134C0BBAF for ; Fri, 9 Oct 2009 08:16:12 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An8BAIZxzkrEGfDbmWdsb2JhbACBUZkyAQEBAQEICwoHE78KhCoE X-IronPort-AV: E=Sophos;i="4.44,530,1249250400"; d="scan'208";a="34566575" Received: from rrba-ip-smtp-2-4.saix.net ([196.25.240.219]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Oct 2009 08:16:11 +0200 Received: from apu.softwarerealisations.com (dsl-240-167-26.telkomadsl.co.za [41.240.167.26]) by rrba-ip-smtp-2-4.saix.net (Postfix) with ESMTP id 4E83F458C for ; Fri, 9 Oct 2009 08:16:08 +0200 (SAST) Received: from www.softwarerealisations.com (localhost.localdomain [127.0.0.1]) by apu.softwarerealisations.com (8.14.2/8.12.10) with ESMTP id n995PfwI026022 for ; Fri, 9 Oct 2009 07:25:41 +0200 Received: from 41.177.16.252 (SquirrelMail authenticated user rouanvd); by www.softwarerealisations.com with HTTP; Fri, 9 Oct 2009 07:25:41 +0200 (SAST) Message-ID: <53322.41.177.16.252.1255065941.squirrel@41.177.16.252> Date: Fri, 9 Oct 2009 07:25:41 +0200 (SAST) Subject: Why type inference fails in this code From: rouanvd@softwarerealisations.com To: caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Spam: no; 0.00; inference:01 compiler:01 ocaml:01 inference:01 messes:01 foo:01 haskell:01 infers:01 foo:01 workarounds:01 int:01 int:01 string:02 string:02 workaround:03 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.