Re:Learn Physics by Programming in Haskell
by tome on Saturday February 24, 2018 @01:22PM
(#16454516)
Yes indeed. Not only is it possible to overload + but Haskell's type system has absolutely nothing to say on the matter.
Yes but if you want to use libs, and they don't do it this way, you're f--ked. This is one of the things I ran into.
Re:Learn Physics by Programming in Haskell
by dllthomas on Sunday February 25, 2018 @06:46PM
(#16461935)
Well, no, you're not "f--ked", there's just a pile of boilerplate. Not fun - and likely not worth it for the marginal benefit of being able to reuse + that way - but plenty possible.
And for what it's worth, I certainly agree that the way Num is structured is a wart in Haskell, and I think the previous two commenters agree. It's just that we should be clear about where the blame lies - and that's not the type system.
Haskell’s type system does not prevent you from overloading the + operator. It’s the standard library (“Prelude”) that defines + to only work on numbers, and not on vectors, but with Haskell’s type system allows you to define + to do anything you want.