From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA08195; Sun, 7 Apr 2002 17:48:12 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA09469 for ; Sun, 7 Apr 2002 17:48:11 +0200 (MET DST) Received: from lobus.fungible.com (adsl-64-161-114-6.dsl.snfc21.pacbell.net [64.161.114.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g37Fm9X11676 for ; Sun, 7 Apr 2002 17:48:10 +0200 (MET DST) Received: by lobus.fungible.com (Postfix, from userid 1000) id 98EE97F5D; Sun, 7 Apr 2002 08:48:07 -0700 (PDT) Date: Sun, 7 Apr 2002 08:38:54 -0700 From-Tims-Fingers: true To: oliver@first.in-berlin.de Cc: caml-list@inria.fr In-reply-to: (message from Oliver Bandel on Sat, 6 Apr 2002 19:52:34 +0200 (MET DST)) Subject: Re: [Caml-list] Records with same structure in OCaml References: Message-Id: <20020407154807.98EE97F5D@lobus.fungible.com> From: tim@fungible.com (Tim Freeman) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >type complex = { re: float; im: float }; >type foo = { re: float; im: float }; > >let x = { re =2.0; im = 55.0 }; > > >The x here has type foo. >How can I choose type complex? >>From experiments with the system it seems that declaring foo binds new meanings to the .re and .im field operators. Before the declaration they fetched fields from complex numbers, and after the declaration they fetch fields from "foo". After doing your code above, the following happens: ># x.re ;; >- : float = 2 ># type complex = { re: float; im: float };; >type complex = { re : float; im : float; } ># x.re;; >Toplevel input: ># x.re;; > ^ >This expression has type foo but is here used with type complex See how the redeclaration of complex changes the meaning of ".re" so you can't get "x.re" any more, if x is a foo. If the field operators were ambiguous, that would make type inference much more difficult, so I'm not surprised by this. If we have the declaration let z y = y.re;; then we can give z the type complex -> float, or foo -> float, but there's no way within OCaml's language of types to express (either a complex or foo) -> float. Thus type inference needs a commitment that .re either takes a complex or a foo, but not either. -- Tim Freeman tim@fungible.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners