Re:Why Haskell?
by yakshaving_jgt on Saturday September 14, 2024 @03:35PM
(#41542229)
But now you’re talking about something else aren’t you? Now you’re talking about generalising. You can generalise, for example, from Float to Floating a => a. But I don’t understand how the original Int to Maybe Int change could be sensible. How does that work?
Re:Why Haskell?
by magicalhippo on Saturday September 14, 2024 @09:00PM
(#41544307)
The exact same way? Or perhaps you could tell me, in which cases can an Int not be turned into a Maybe Int?
Again, I don't know Haskell, so from the outside it looks like much the same as the float -> complex conversion.
Re:Why Haskell?
by yakshaving_jgt on Sunday September 15, 2024 @12:17PM
(#41548359)
It sounds like you need to learn about parametricity.
It doesn't sound like that to me. Could you not just answer his question?
Re:Why Haskell?
by yakshaving_jgt on Monday September 16, 2024 @04:08AM
(#41553856)
To whom shall I send the invoice?
The compiler should not "just" know it. It would know it because we told it how.
Consider a function that takes a float and returns a complex number. I then change the function to take a complex number ("Complex Float" in Haskell if I read the docs right), and returns a float.
I could then tell the compiler, by implementing an implicit cast operator, how to cast float to complex. The implicit part is then that the compiler tries it without me telling it to use the cast explicitly.
Then any code that worked with the old function should work perfectly fine using the modified function without modifications, since per definition the reals are contained in the complex numbers.
This is how I do it in several languages I've used.