* [Caml-list] serious type confusion @ 2004-03-27 17:31 briand 2004-03-27 17:55 ` briand 2004-03-27 18:16 ` Matt Gushee 0 siblings, 2 replies; 4+ messages in thread From: briand @ 2004-03-27 17:31 UTC (permalink / raw) To: caml-list 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 ? Thank You Brian ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Caml-list] serious type confusion 2004-03-27 17:31 [Caml-list] serious type confusion briand @ 2004-03-27 17:55 ` briand 2004-03-27 18:16 ` Matt Gushee 1 sibling, 0 replies; 4+ messages in thread From: briand @ 2004-03-27 17:55 UTC (permalink / raw) To: caml-list I am in awe of type inferencing. Sure enough I checked the code and I was using current_polyline in a manner inconsistent with a point list. never mind... Brian ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] serious type confusion 2004-03-27 17:31 [Caml-list] serious type confusion briand 2004-03-27 17:55 ` briand @ 2004-03-27 18:16 ` Matt Gushee 2004-03-27 18:34 ` briand 1 sibling, 1 reply; 4+ messages in thread From: Matt Gushee @ 2004-03-27 18:16 UTC (permalink / raw) To: caml-list 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] serious type confusion 2004-03-27 18:16 ` Matt Gushee @ 2004-03-27 18:34 ` briand 0 siblings, 0 replies; 4+ messages in thread From: briand @ 2004-03-27 18:34 UTC (permalink / raw) To: Matt Gushee; +Cc: caml-list >>>>> "Matt" == Matt Gushee <mgushee@havenrock.com> writes: Matt> * Is current_polyline defined within the same scope where the error Matt> occurs, or is it received as an argument? If it is the latter, and Matt> somewhere before the error location there is an expression that *uses* Matt> !current_polyline as a point, that would explain your error. If your Matt> function is too complex to easily identify the problem by sight, an Matt> easy way to check for this would be to put a type constraint on the Matt> parameter: Matt> let myfun (current_polyline:point list ref) = Matt> .... That was it exactly (see my followup). However that's a very nice trick for future debuggin effort. Thanks Brian ------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-03-27 18:34 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-03-27 17:31 [Caml-list] serious type confusion briand 2004-03-27 17:55 ` briand 2004-03-27 18:16 ` Matt Gushee 2004-03-27 18:34 ` briand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox