Hacker News new | past | comments | ask | show | jobs | submit login

This is a valid point, but now you have two ways of representing a square and you need the coversion functions.

It's better than nothing as you can guarantee that an instance of Square is a square, but you still need to handle squares disguised as Rectangle.

You could throw in dependent types and force rectangles to have different width and height, but that doesn't really help in getting nicer API.

If I had to do something like this in a real program I would take these issues as a sign that I need to step back and re-evaluate my design. I'd look at what I want to use these types for and try to come up with the best approach for that specific case.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: