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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0F33DBBC1 for ; Sun, 23 Mar 2008 23:20:45 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArIBADJ05kdCbwQZk2dsb2JhbACRFwEBAQEJBQcJFJQr X-IronPort-AV: E=Sophos;i="4.25,544,1199660400"; d="scan'208";a="9867927" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Mar 2008 23:20:44 +0100 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id A4A31DF0CB; Sun, 23 Mar 2008 18:20:43 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Sun, 23 Mar 2008 18:20:43 -0400 X-Sasl-enc: UNiK9Sk7uth1nKqFSLur3umkWyfpKDMGODP6uvR5jhTi 1206310843 Received: from [192.168.1.10] (ALyon-157-1-20-67.w81-251.abo.wanadoo.fr [81.251.179.67]) by mail.messagingengine.com (Postfix) with ESMTPSA id D556A3A53; Sun, 23 Mar 2008 18:20:42 -0400 (EDT) Date: Sun, 23 Mar 2008 23:19:45 +0100 (CET) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Jacques Le Normand Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] type error In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; ens-lyon:01 foo:01 foo:01 val:01 endline:01 val:01 unbound:01 unbound:01 wrote:01 caml-list:01 caml-list:01 constraint:01 int:01 int:01 jambon:01 On Sun, 23 Mar 2008, Jacques Le Normand wrote: > Hello caml-list, > I don't quite understand what the error is here: > > type foo = > > error: > > A type variable is unbound in this type declaration. > In definition < bar : int; .. > the variable 'a is unbound Basically ".." means "any number of methods of any kind", which needs to be represented by a type variable. You can do something like this, which is probably not very useful: # type 'a foo = < bar: int; .. > as 'a;; type 'a foo = 'a constraint 'a = < bar : int; .. > A more idiomatic way is to declare the following type: type foo = < bar: int > And when you need an object to behave as having type foo, you use ":>" to hide the extra methods. # type foo = < bar: int >;; type foo = < bar : int > # let print_bar (x : foo) = print_int x # bar;; val print_bar : foo -> unit = # let x = (object method bar = 123 method hello () = print_endline "hello" end);; val x : < bar : int; hello : unit -> unit > = # print_bar x;; This expression has type < bar : int; hello : unit -> unit > but is here used with type foo Only the first object type has a method hello # print_bar (x :> foo);; 123- : unit = () Martin -- http://wink.com/profile/mjambon http://martin.jambon.free.fr