5 ms·
Modules are strictly more powerful than Haskell type classes (at least, more powerful than naive type classes; there are so many extensions that I'm not sure th
by pauldirac137 10y ago
Modules are strictly more powerful than Haskell type classes (at least, more powerful than naive type classes; there are so many extensions that I'm not sure that is still the case). Modular implicits are described here: http://arxiv.org/pdf/1512.01895.pdf http://arxiv.org/pdf/1512.01895.pdf. The main problem with modules as typeclasses is that it's pretty painful to use in practice, and modular implicits fix that, giving a solution quite reminiscent of Haskell type classes. I don't know Scala implicits well enough to comment, but the authors feel their version avoids most of the problems in Scala's implicits (they jokingly refer to it as "a more explicit kind of implicit").
- lomnakkus 10y agoAFAIUI modular implicits don't give you global uniqueness. While this can be "worked around" in some cases[0], it's not really possible in the general case, and global uniqueness is pretty essential for sanity when writing higher-level code[1]. [0] The paper gives set-union as an example. [1] https://www.youtube.com/watch?v=hIZxTQP1ifo https://www.youtube.com/watch?v=hIZxTQP1ifo . (Sorry for throwing video at you -- there's probably a write-up somewhere, but I'm in a bit of a rush, and this was the thing that came to mind.)
- airless_bar 10y ago> [1] https://www.youtube.com/watch?v=hIZxTQP1ifo https://www.youtube.com/watch?v=hIZxTQP1ifo Now we just need a Haskell compiler which actually bothers to provide the "pretty essential for sanity" for global uniqueness. Currently, I count zero compilers in common use which do.
- lomnakkus 10y agoNot sure what you mean. Could you elaborate?
- airless_bar 10y agoGHC gives you none of the guarantees Kmett keeps boasting about.
- lomnakkus 10y agoHow so? (EDIT: Just to forestall the inevitable: Yes, there are some weird and dangerous extensions you can enable, but mostly it's pretty clear that they're dangerous. It doesn't seem to be a problem in practice.)
- airless_bar 10y ago> How so? Because they never bothered to actually implement the checks to guarantee global uniqueness in GHC? > (EDIT: Just to forestall the inevitable: Yes, there are some weird and dangerous extensions you can enable, but mostly it's pretty clear that they're dangerous. It doesn't seem to be a problem in practice.) No weird and dangerous extensions in use. Vanilla Haskell.
- tome 10y ago> Because they never bothered to actually implement the checks to guarantee global uniqueness in GHC? Sure they did. Orphan instances are detected by the compiler.
- airless_cotton 10y ago(Sorry, forgot password to my old account.) Orphan warnings tell you that you defined an instance in the wrong place. Things you don't receive warnings for: - Defining the same instance twice. - Having code which uses both instances. Those two should be hard compiler errors, because they break data structures at runtime and make code behave incorrectly. Sorry, orphan warnings are multiple magnitudes of escalation levels away from what should happen and are focused on something different (code hygiene vs. THIS-CODE-IS-WRONG-AND-BROKEN-AND-WILL-CORRUPT-SHIT-AT-RUNTIME-I-WILL-FAIL-TO-COMPILE-THIS).