News for hackers. Stuff that matters.
Re:F# 4.0 Preview by AndrewDucker on Thursday November 13, 2014 @04:45AM (#8600703)
Yeah, it looks a lot cleaner - but if you make that code available as a library then other people can't add new shapes easily, or deal with shapes that have more than one length (e.g. a rectangle, which has two).
Re:F# 4.0 Preview by couchand on Thursday November 13, 2014 @09:16AM (#8601563)
Well, yes, you can add a rectangle quite easily:

    type Shape =
        | Circle of float
        | Square of float
        | Rectangle of float * float
The thought about adding new shapes (mentioned several times in this thread) is just misplaced. If you're releasing library code people should not be extending your built-in types, that's bad form -- consumers of a library should interact with it through interfaces only.
Re:F# 4.0 Preview by ufo on Thursday November 13, 2014 @11:05AM (#8602223)
The flipside is that its very easy for your library users write a new function that takes a Shape as a parameter. If you model things with a class hierarchy its easy to add a new Shape subclass but you can't add any new methods to the Shape interface.
Re:F# 4.0 Preview by wwosik on Thursday November 13, 2014 @04:52AM (#8600718)
That comment about shapes with more than one defining size property is very valid.