4 ms·
You can do what you are describing in Haskell just fine. Eg you can implement 'overloaded' arithmetic operations for your custom data types. I think what's de
by eru 2y ago
You can do what you are describing in Haskell just fine. Eg you can implement 'overloaded' arithmetic operations for your custom data types.
I think what's described in the article goes a lot further than this. (Though I'm not sure it's worth it.)
Compare also https://okmij.org/ftp/tagless-final/ https://okmij.org/ftp/tagless-final/
- comex 2y agoI didn't mean to imply that you couldn't do the same in Haskell without the extra type-checking tricks in the article. I guess my main point is that the actual runtime semantics – like, if you take away the type checking, which functions are being called on what – are no different from what you'd see in Python. That differs from a lot of other Haskell techniques, where a direct port to Python would include tons of nested lambdas (which are relatively awkward in Python, and indeed in most imperative languages), and would also be fairly error-prone without the type checker to keep things straight. Even relatively simple uses of do notation fall into that category.
- eru 2y agoYou can directly port the Python technique you mentioned without any extra closures. (I mean not more than the normal amount of closures you'd get from straight-forward code that just calculates the answer as a number, instead of giving you the AST.)
- cryptonector 2y agoIn Python you get run-time typing and dispatch. In Haskell you get static typing [and monomorphisation]. GP means that static typing is safer and faster.
- eru 2y agoYou can do the same AST trick in a type safe manner.