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.7 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,MISSING_HEADERS,SPF_FAIL autolearn=disabled version=3.1.3 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 E62C3BBAF for ; Tue, 21 Apr 2009 03:44:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AukAAEfB7EnY/EBGlGdsb2JhbACNG4kjAQEBAQkLCAkRBLlkg30G X-IronPort-AV: E=Sophos;i="4.40,220,1238968800"; d="scan'208";a="26547715" Received: from mailhost1.enter-net.com ([216.252.64.70]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 Apr 2009 03:44:53 +0200 Received: (qmail-ldap/ctrl 31858 invoked from network); 21 Apr 2009 01:53:35 -0000 Received: from 63-80-252-216-dsl.colba.net (HELO [192.168.0.100]) ([216.252.80.63]) (envelope-sender ) by mailhost1.enter-net.com (qmail-ldap-1.03) with SMTP for ; 21 Apr 2009 01:53:35 -0000 Message-ID: <49ED2516.9030103@colba.net> Date: Mon, 20 Apr 2009 21:44:54 -0400 From: Eliot Handelman Reply-To: eliot@colba.net User-Agent: Thunderbird 2.0.0.6 (X11/20070801) MIME-Version: 1.0 Cc: caml-list@inria.fr Subject: Polymorphism problem References: <200904202215.27735.jon@ffconsultancy.com> In-Reply-To: <200904202215.27735.jon@ffconsultancy.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; polymorphism:01 polymorphic:01 rec:01 rec:01 surprising:01 int:01 int:01 seems:03 workaround:03 let:03 let:03 problem:05 intermediate:05 i'd:06 function:08 Hi list, Consider this: type 'a x = { x_v : 'a } and 'a y = { y_x : int kind; y_arr : 'a array } and 'a kind = X of 'a x | Y of 'a y I'd like to write a function _getter_ that's polymorphic over kind. This doesn't work, getting int kind -> int: let rec getter = function X x -> x.x_v | Y y -> y.y_arr.(getter y.y_x) which seems surprising to me since getter y.y_x is an intermediate value that's never returned. Is this just a limitation of the type system or does this result make sense? Here's my workaround: let rec int_getter = function X x -> x.x_v | Y y -> (int_getter y.y_x) let rec getter = function X x -> x.x_v | Y y -> y.y_arr.(int_getter y.y_x) where now the type of getter is 'a kind -> 'a as needed. I have no choice but to use this at present -- is there a better method? thanks for wisdom, -- eliot