| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I have a problem :-D. I need to define two different types point2 and point3: type point2 = {x:float; y:float} type point3 = {x:float; y:float; z:float} Because I need to make operations with 2d & 3d points. The problem is when I need to create a point2 variable: # {x=0.;y=0.};; Some record field labels are undefined: z # let (p : point2) = {x=0.; y=0.};; Some record field labels are undefined: z Creating a point3 variable I have no problem: # {x=0.;y=0.;z=0.};; - : point3 = {x = 0.; y = 0.; z = 0.} Ocaml cannot differentiate between point2 & point3 types. How I can make a point2 variable? |
|
#2
| |||
| |||
| It's a FAQ: http://caml.inria.fr/FAQ/FAQ_EXPERT-...bels_surcharge On Tue, 5 Aug 2003 20:28:26 +0000 (UTC), samsaga2 <samsaga2@menta.net> wrote: > I have a problem :-D. I need to define two different types point2 and point3: > > type point2 = {x:float; y:float} > type point3 = {x:float; y:float; z:float} > > Ocaml cannot differentiate between point2 & point3 types. How I can make > a point2 variable? |
|
#3
| |||
| |||
| In article <bgu0nd$1v5$1@wolfberry.srv.cs.cmu.edu>, Rob Arthan wrote: > Julian Brown wrote: > >> In article <bgp41a$k6d$1@wolfberry.srv.cs.cmu.edu>, samsaga2 wrote: >>> I have a problem :-D. I need to define two different types point2 and >>> point3: >>> >>> type point2 = {x:float; y:float} >>> type point3 = {x:float; y:float; z:float} >>> >>> Because I need to make operations with 2d & 3d points. The problem is >>> when I need to create a point2 variable: >>> >>> # {x=0.;y=0.};; >>> Some record field labels are undefined: z >>> >>> # let (p : point2) = {x=0.; y=0.};; >>> Some record field labels are undefined: z >>> >>> Creating a point3 variable I have no problem: >>> >>> # {x=0.;y=0.;z=0.};; >>> - : point3 = {x = 0.; y = 0.; z = 0.} >>> >>> Ocaml cannot differentiate between point2 & point3 types. How I can make >>> a point2 variable? >> >> This is in the FAQ, see: >> >> http://caml.inria.fr/FAQ/FAQ_EXPERT-...bels_surcharge >> >> Jules > > Yucch! This is how really prehistoric C compilers treated structure member > names - and it's a feature in Ocaml? It is pretty gruesome I think, but at least the scope for member names is only the current module (ie, source file under normal circumstances, unless you "open" things or make sub-modules as in the FAQ entry). Possibly, alternatives would involve nasty (from the compiler's point of view) context-sensitivity in the syntax. How would you prefer it to work? Better stop before I get way out of my depth ;-) Jules |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.