31.07.2013 Views

Adobe PDF

Adobe PDF

Adobe PDF

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Subtyping - Rules<br />

Subtyping and Structures<br />

Consider<br />

type Point = struct { x:Int, y:Int };<br />

And<br />

type ColorPoint = struct { x:Int, y:Int, c:Color };<br />

Intuitively, all ColorPoints are Points since they<br />

include x:Int and y:Int fields<br />

So, model Point and ColorPoint as follows:<br />

Point = { (('x',x),('y',y))| x:Int, y:Int }<br />

ColorPoint =<br />

{ (('x',x),('y',y)) | (('x',x),('y',y)) is a member of Point<br />

with additional attribute c:Color }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!