<div dir="ltr">I've linked to an ugly attempt to emulate subclasses in Haskell, and I'm wondering if anyone has done what I have perhaps in a cleaner way. <div><br></div><div>Firstly, the code is here: <a href="http://ideone.com/znHfSG">http://ideone.com/znHfSG</a></div><div><br></div><div>To explain what I've done, I first thought that a "method" basically takes some "input" (which I've called "i"), an object (which I've called "c" for class) and returns some output "o" and a potentially modified object "c". I've captured this behaviour in the badly named class "C".</div><div><br></div><div>I've then made a class "User", with methods "getFirstName" and "putFirstName" and defined them appropriately.</div><div><br></div><div>Furthermore, I've then made a data type "Age", and then "ExtendedUser" which combines "User" with "Age".</div><div><br></div><div>At this point, I can still call "getFirstName" and "putFirstName" on "ExtendedUser", as would be hoped.</div><div><br></div><div>I also defined "getAge", which naturally works on ExtendedUser.</div><div><br></div><div>Furthermore, I can override "getFirstName" on "ExtendedUser", which I have done to instead return a capitalised version.</div><div><br></div><div>Is what I've done of any practical use? And has someone done it better than me?</div></div>