From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A250E7FBBC for ; Wed, 7 Jan 2015 16:30:16 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of goswin-v-b@web.de designates 212.227.17.12 as permitted sender) identity=mailfrom; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlMAAJBQrVTU4xEMnGdsb2JhbABc0FYCgQ9DAQEBAQERAQEBAQEGDQkJFC6EDQEFJxNPCyElDwUoIYgqARQEvyEfg38BCwEfj3+DFoETBZcthgEMi1iEEYMxAQEB X-IPAS-Result: AlMAAJBQrVTU4xEMnGdsb2JhbABc0FYCgQ9DAQEBAQERAQEBAQEGDQkJFC6EDQEFJxNPCyElDwUoIYgqARQEvyEfg38BCwEfj3+DFoETBZcthgEMi1iEEYMxAQEB X-IronPort-AV: E=Sophos;i="5.07,715,1413237600"; d="scan'208";a="95635824" Received: from mout.web.de ([212.227.17.12]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Jan 2015 16:30:16 +0100 Received: from frosties.localnet ([134.3.241.185]) by smtp.web.de (mrweb101) with ESMTPSA (Nemesis) id 0Ljaei-1XXd092PXs-00bcB5 for ; Wed, 07 Jan 2015 16:30:14 +0100 Received: from mrvn by frosties.localnet with local (Exim 4.82) (envelope-from ) id 1Y8sYj-0005HS-KX for caml-list@inria.fr; Wed, 07 Jan 2015 16:30:09 +0100 Date: Wed, 7 Jan 2015 16:30:09 +0100 From: Goswin von Brederlow To: caml users Message-ID: <20150107153009.GD17784@frosties> References: <20150107135012.GA17784@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150107135012.GA17784@frosties> User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:uxQqWcZvjfzSjtOdCmxcEBAKeuQlJQJeBo+H2TQ+mY4RMc9Spxb K59dTEflyLUQMrsUqAQkCthjhu+FJvEcWOzVhg+Gk3pILSLwZPyRPFNmoaFINAFjCRjrK5H 75lWYQOuAT5Za7CVYecNjo182M4G/uNZNs9mDS0yAuBNa7Zv+AX2ugTzd68CDnf7V6m3uTi jcW7GgYcz0Qw9K84w10Ag== X-UI-Out-Filterresults: notjunk:1; Subject: Re: [Caml-list] Problem with universal functions in a module Somehow the example code got lost: module M = struct type _ t = Int : int -> int t | Float : float -> float t let print : type a . a t -> unit = function | Int i -> Printf.printf "%d\n" i | Float f -> Printf.printf "%f\n" f (* should be abstract *) type box = Box : 'a t -> box let box t = Box t (* let call_unboxed fn (Box t) = fn t Error: This expression has type a#0 t but an expression was expected of type a#0 t The type constructor a#0 would escape its scope *) (* should be abstract *) type 'a helper = { fn : 'b . 'b t -> 'a } (* let helper fn = { fn } Error: This field value has type 'c t -> 'd which is less general than 'b. 'b t -> 'a *) let call helper (Box t) = helper.fn t end open M let t = [box (Int 1); box (Float 2.0)] (* Works but is not possible if box is abstract *) let () = List.iter (function Box x -> print x) t (* Use conversion helper to call unboxed values with a function *) let h = { fn = print } let () = List.iter (call h) t MfG Goswin