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 TAA04702; Sat, 27 Mar 2004 19:16:42 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA04757 for ; Sat, 27 Mar 2004 19:16:40 +0100 (MET) Received: from mz1.forethought.net (mzpi3.forethought.net [216.241.36.12]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2RIGcHd018294 for ; Sat, 27 Mar 2004 19:16:39 +0100 Received: from [216.241.35.41] (helo=swordfish) by mz1.forethought.net with esmtp (Exim 4.30) id 1B7IMI-0004zx-2x for caml-list@pauillac.inria.fr; Sat, 27 Mar 2004 11:16:38 -0700 Received: from matt by swordfish with local (Exim 3.35 #1 (Debian)) id 1B7IMJ-0002CP-00 for ; Sat, 27 Mar 2004 11:16:39 -0700 Date: Sat, 27 Mar 2004 11:16:38 -0700 From: Matt Gushee To: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] serious type confusion Message-ID: <20040327181638.GA8360@swordfish> Reply-To: Matt Gushee Mail-Followup-To: caml-list@pauillac.inria.fr References: <16485.47700.498923.656556@soggy.deldotd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16485.47700.498923.656556@soggy.deldotd.com> User-Agent: Mutt/1.3.27i X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; gushee:01 mgushee:01 havenrock:01 caml-list:01 2004:99 val:01 myfun:01 list':01 list':01 gushee:01 englewood:01 manure:01 mgushee:01 havenrock:01 ignores:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 395 On Sat, Mar 27, 2004 at 09:31:00AM -0800, briand@aracnet.com wrote: > > OK, this is what I get for coding too long in scheme :-) > > observe the following: > > # let a=ref [];; > val a : '_a list ref = {contents = []} > # a := {x=0.;y=0.;z=0.} :: [];; > - : unit = () > # !a;; > - : point list = [{x = 0.; y = 0.; z = 0.}] > # a := {x=0.;y=0.;z=0.} :: !a;; > - : unit = () > # !a > ;; > - : point list = [{x = 0.; y = 0.; z = 0.}; {x = 0.; y = 0.; z = 0.}] > # > > Exactly as expected ! types aren't so bad after all.. until here : > > current_polyline := {x=wx; y=wy; z=wz} :: !current_polyline; > > This expression has type point but is here used with type point list > > Huh? The first example worked. Oh I see, it's operator precedence, > it's assigning the point before doing the concatenation. Oh but wait, > it worked in the previous example. I'll try and fix it anyway... > > current_polyline := ({x=wx; y=wy; z=wz} :: !current_polyline); > > This expression has type point but is here used with type point list > > Huh ??? Isn't that impossible ? I've triple checked and > current_polyline is always consistently used as a list, and more > importantly a point list... > > Any hints ? Hints, yes. Hard to say for sure without seeing more of your code, but two things that occur to me offhand are: * Is current_polyline defined within the same scope where the error occurs, or is it received as an argument? If it is the latter, and somewhere before the error location there is an expression that *uses* !current_polyline as a point, that would explain your error. If your function is too complex to easily identify the problem by sight, an easy way to check for this would be to put a type constraint on the parameter: let myfun (current_polyline:point list ref) = .... That way you'll get an error on entry into the function if current_polyline is wrongly defined in the calling scope. If, on the other hand, there was an expression that tried to use the value as a point, it will now fail. * Pay attention to *exactly* which expression is causing the error-- i.e., not just the line number, but also the position in the line. Is it possible that !current_polyline is actually a 'point list list' rather than a 'point list'? If so, then of course the new element you add to it must be a 'point list'. Hope this helps. -- Matt Gushee When a nation follows the Way, Englewood, Colorado, USA Horses bear manure through mgushee@havenrock.com its fields; http://www.havenrock.com/ When a nation ignores the Way, Horses bear soldiers through its streets. --Lao Tzu (Peter Merel, trans.) ------------------- 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