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=2.3 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 398FABBAF for ; Fri, 9 Oct 2009 08:55:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmsBACN7zkpKfU4bimdsb2JhbACRQYkDPwEBAQoJDAcRBa4HgTuPVwEDAwWEJQQ X-IronPort-AV: E=Sophos;i="4.44,530,1249250400"; d="scan'208";a="35983338" Received: from ey-out-2122.google.com ([74.125.78.27]) by mail3-smtp-sop.national.inria.fr with ESMTP; 09 Oct 2009 08:55:04 +0200 Received: by ey-out-2122.google.com with SMTP id 22so1416996eye.31 for ; Thu, 08 Oct 2009 23:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:in-reply-to:subject :x-priority:references:message-id:content-type :content-transfer-encoding:mime-version:date:cc:x-mailer; bh=NqKiW7plz+QaoFUytNEdRaH2rCNBfv/pQMEa0/6NeEU=; b=AvC9bxmuvjUBR/6sSMkdr57Zby1JA2lFHagzNYKzJk9Fgp/EUKFT1OM6+VLjWBHkHS a2JEuEhUfCE+QJvnNSyUSKgWXRbfXi4AzOenum/Kh0LXvzeu0qhm20/5+h224IaZ4SeE 0YWOqNPsZK0bvWm6sxoE7QOUKxS4/f4HdP+Uo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:in-reply-to:subject:x-priority:references:message-id :content-type:content-transfer-encoding:mime-version:date:cc :x-mailer; b=AWE3/IJINeinzlmZN33BLDVaUql74M2PTvAqcbevJXtFBAJ/Z7iwgTCA2dmBOdE8tf O8pH85cnd9jrlxUNn3X2Mmk3JWlw20jl686XA9XnEBEQWMLOyW/T3K6RuBb0yuf2ryed +eORwWYXxb2bKEP5QtAdANqV/pbaEjCEqxLK0= Received: by 10.210.7.21 with SMTP id 21mr9440634ebg.66.1255071304002; Thu, 08 Oct 2009 23:55:04 -0700 (PDT) Received: from ?192.168.0.11? (tui75-1-81-57-73-233.fbx.proxad.net [81.57.73.233]) by mx.google.com with ESMTPS id 23sm744133eya.42.2009.10.08.23.55.00 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 08 Oct 2009 23:55:02 -0700 (PDT) From: Vincent Aravantinos To: rouanvd@softwarerealisations.com In-Reply-To: <53322.41.177.16.252.1255065941.squirrel@41.177.16.252> Subject: Re: [Caml-list] Why type inference fails in this code X-Priority: 3 (Normal) References: <53322.41.177.16.252.1255065941.squirrel@41.177.16.252> Message-Id: <668FA99E-41F3-4BEF-9F55-2C45DEE6CAD3@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Apple Message framework v936) Date: Fri, 9 Oct 2009 08:54:58 +0200 Cc: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.936) X-Spam: no; 0.00; inference:01 foo:01 workarounds:01 polymorphes:01 haskell:01 infers:01 foo:01 haskell:01 compiler:01 annotations:01 faq:01 faq:01 caml-list:01 ghc:01 int:01 Le 9 oct. 09 =E0 07:25, rouanvd@softwarerealisations.com a =E9crit : > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > type t =3D MyInt of int | MyFloat of float | MyString of string ;; > > let foo printerf =3D function > | MyInt i -> printerf string_of_int i > | MyFloat x -> printerf string_of_float x > | MyString s -> printerf (fun x -> x) s > ;; > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > I read that there are lots of workarounds for the above code =20 > snippet, but > I would like to > Know why this code fails and what is the best workaround for this =20 > type of > code. You might find some answers here: = http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#arguments_p= olymorphes Though this won't clearly tell you "why", and I sadly don't know the =20 answer. =46rom my experience the type system limitations are not so big =20 hindrance in practice, you may have to work a bit to get what you want fit in the type system, but I've never found a thing that wouldn't work at all. BTW: > I have done the same thing in Haskell and it correctly infers the =20 > type of > foo. It doesn't work for me with ghc 6.10.3. I mean, unless you provided the Haskell compiler with some type =20 annotations the same error occurs. But I am not a haskell expert so I may be wrong. V.=