3 ms·
This is a good discussion of a problem that suits Haskell well, but it's unfair to Python in some respects. For example: I haven't read or written a lot of Pyt
by tom_mellior 7y ago
This is a good discussion of a problem that suits Haskell well, but it's unfair to Python in some respects.
For example: I haven't read or written a lot of Python in a while, but would Python programmers really want to implement mutation in such a class by copying dicts around? The hand-wringing about "oh no, I wrote the condition as not is_node" is silly since one could just define an is_leaf method that can be used without negation. And "changing heapToList to return a lazy sequence makes it no longer return a list, oh no!" is just as silly, since one would of course not do that but define a separate heapToSequence (and probably base heapToList on that).
Also: "pattern matching and algebraic data types which have massive, clear benefits and few (if any) downsides". They have downsides whenever your data is not tree-shaped. Yes, a lot of data is tree, but then a lot isn't. I work in compilers, which is often touted as a prime application of ML-family languages, and this is very true, but not 100%. If you can have sharing in your abstract syntax tree (like a goto node that might refer to a target node somewhere else in the tree), you start to have difficulties. And you get even more difficulties when you try to model control flow graphs and the like. Nothing insurmountable, but still things where it's suddenly good to have other tools than only algebraic datatypes. OCaml is good in this regard.
- platz 7y agoYou are free to use a Map in Haskell whenever it suits you. Nothing requires to to use ADTs when it would not make sense to do so.
- tom_mellior 7y agoSure, I said the issue was not insurmountable. But (and yes, I know Haskell programmers won't necessarily agree) there are contexts in which following a direct, mutable reference is superior to indirecting through a map.
- platz 7y agoSure, Desktop GUI programming tends to be one of those contexts. But I think those contexts are much rarer in Server APIs, and the internet has shifted the focus of programming from GUIs to APIs. I wouldn't recommend Hsakell for a desktop GUI, but it's excellent in the API world. It's more of a backend language.
- leshow 7y agoThere are some really cool things in haskell-gi. Haskell has the ability to make some wonderful DSLs. Have a look: https://haskell-at-work.com/episodes/2018-11-13-gtk-programming-with-haskell.html https://haskell-at-work.com/episodes/2018-11-13-gtk-programm...