Jump to content
  • Advertisement
Sign in to follow this  
cinag

OO emulated by ML with record concatenation

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm currently reading a lot about programming language and I’m trying to find a small subset of functionalities I would like to add to a new ML programming language and I'm wondering what has happened to "record concatenation". It seems to me a way to merge OO (maybe more prototype oriented programming) and ML. Nevertheless no research seems to go in this direction... I'm wondering why! For example, one could write: let dog = { weight = 10; bark = (fun () -> print "Waouf\n") } let mydog = dog with { weight = 2; tiny = true } In this case, weight is overridden and tiny is a new field. If someone has a clue of why this kind of functionalities is not used, please tell me! Many thanks [Edited by - cinag on July 9, 2006 7:06:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
Or if someone has a set of functionalities that give the encapsulation power of object with minimum modification of the ML language and without any complex construct.

Share this post


Link to post
Share on other sites
What you propose would require an overhauling of the ML typing system, which supports generalization but not supertypes. That system was introduced in O'Caml for instance (albeit with a slightly different syntax) :


class dog = object
method weight = 10
method bark () = print_endline "Waouf"
end

class mydog = object
inherit dog
method weight = 2
method tiny = true
end


The problem here is that you will need to introduce a way to represent the actual fields. In ML, records are identified by their fields, so using the field weight would identify one and only one type (which?). To work around this, O'Caml introduces two parallel type schemes. The first is the anonymous class system:

< bark : unit -> unit; weight : int >

That is, a class is represented only by its public members. It gets somewhat tricky to use and you need to perform the casting manually (because supertyping might cause you to lose information). The alternative is class-name-based typing: you give names to such types, and allow conversions through the inherit keyword. In this case, mydog and dog are two types, and mydog can be supertyped into dog, which can be supertyped into
< bark : unit -> unit; weight : int >.

Note that the supertying operator :> does not exist in ML at all, and was introduced to manage supertypes correctly.

Also, check this text out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!