Different types with equal fields

This is a discussion on Different types with equal fields within the ml forums in Programming Languages category; 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 ...

Go Back   Application Development Forum > Programming Languages > ml

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-05-2003, 04:28 PM
samsaga2
Guest
 
Default Different types with equal fields

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?



Reply With Quote
  #2  
Old 08-05-2003, 05:49 PM
Manos Renieris
Guest
 
Default Re: Different types with equal fields

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?


Reply With Quote
  #3  
Old 08-12-2003, 07:01 PM
Julian Brown
Guest
 
Default Re: Different types with equal fields

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

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:48 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.