7 ms·
The Four Flaws of Haskell
- ioseph 10y agoReadability : although I'm not proficient in Haskell it seems to lend itself towards perl-like clever one liners.
- rtpg 10y agoI share this feeling , esp. when each third party lib wants to introduce some variant of <$../<>). But I've found some of the more common symbols end up being how you think about your code when you become more versed. The big one is <$> for fmap. If you have some functor/monad/thingy, you'll often be like "I have this pure function that I want to apply to the inner value of my functor", and <$> is the perfect analog to $. The high abstraction level of Haskell makes reaching for these really tempting and easy. And the alternatives are verbose and harder to read in many situations. compare "capitalise <$> readStrLn" to do val <- readStrLn return capitalise val (though "fmap capitalize readStrLn" isn't too bad)
- taylorfausak 10y agoThis post explores the differences in those two styles: http://www.yesodweb.com/blog/2015/10/beginner-friendly-code-and-apis http://www.yesodweb.com/blog/2015/10/beginner-friendly-code-... > It seems like my progression as a Haskeller results in forcing myself to write in a harder-to-parse style to make my code shorter, to satisfy some base need for "better" code, even though by most measurements I just made, the longer/explicit/pattern matching code is in fact better.
- chriswarbo 10y agoTo be fair, "<$>" is a synonym for "fmap", so "fmap capitalise readStrLn" is the go-to alternative. The "do" example is not only more verbose, but less general (it only applies to monads rather than all functors), and relies on special syntax (despite its awkwardness, "<$>" is still just a function call). You could also do "capitalise `fmap` readStrLn", which is kind of intermediate between the two :)
- Iceland_jack 10y ago`ApplicativeDo`[1] do-notation works with Functors [1] https://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#ghc-flag--XApplicativeDo https://downloads.haskell.org/~ghc/master/users-guide/glasgo...
- Ericson2314 10y agoThe article is about things that impact professionals (thought they also beginners). For better or worse, experienced Haskell users can read the one liners just fine.
- b34r 10y agoSure, but you've also nuked a developer's ability to easily onboard and understand the codebase with "clever" one liners. Good, maintainable code tends to trend toward lower cognitive load more often than compact solutions.
- nilkn 10y agoI'm generally of this opinion, but with Haskell I think more often than not the "clever" one liners are actually not clever -- they're just completely standard usages of fundamental language constructs, and they only appear clever to people who haven't used the language. It's very common to see newcomers or people who've never used Haskell at all mention <$> and friends in this regard. Then someone will say that if you just used do notation explicitly it'd be a lot clearer. And then someone will point out that do notation might look familiar, but semantically it can be spectacularly different from what one might expect from truly imperative languages (e.g., when using the nondeterminism of the list monad). So by encouraging overuse of do notation, you're making the code feel familiar, but you're not actually making it more understandable; if anything, you're making it harder to understand, because you're making it look like something that it's not. Additionally, while do notation is very generic and broadly powerful, <$> does exactly one thing: it applies a function to a wrapped value, producing a new wrapped value. Once you've used Haskell a fair bit, you very strongly internalize this and tend to immediately understand code involving <$>. If all this code were expanded out to use do notation, you'd have to spend a lot of extra timing reading through the do notation to realize that, oh, this is just a re-implementation of fmap, over and over again.
- blowski 10y agoIs that then a limitation of the language? I've only briefly toyed with Haskell (and most of the time I use PHP, so my opinion is almost moot). But from what you've written, it sounds like it's hard to write Haskell that's expressive for novices and experts at the same time.
- thesz 10y agoThe less decisions you make through you programming day, the more you achieve and the less stressful the job is. Naming variables is a decision (I am looking at you, function arguments in most mainstream languages). Naming variables once and for all is a big and heavy decision (and now it is time for class members to be looked at). For one operator in Haskell I often have to invent names for three-to-five variables in C#.
- tikhonj 10y agoThat's a great way of putting it. Sure, sometimes an intermediate name helps—that's when I reach for `where` or `let`. But much of the time the extra name would just be extra noise that obscures what the code is doing and makes it harder to read at a glance.
- eof 10y agoInteresting, readability is something I would put on a list of upsides of Haskell. I agree that the abundant use of operators can make things difficult in some cases, but this is largely naivety on the part of the reader rather than complexity like Perl. Perl's obfuscated one-liners are just vanilla things that every perl programmer will understand, while Haskell's weird lines are generally package specific operators that one needs to become familiar with. Once familiar (unlike in Perl) a seasoned Haskeller will be able to grok a lot of what is going on very quickly. As a further point, the strictness of it all makes understanding the entire system a much easier experience than many other languages.
- hyperpape 10y agoI suspect that there's a grab bag of things that happen in those one liners, and whether they are a good idea or not depends on the details. For instance, <$> seems pretty helpful, but I shudder when I see flip. I'd go out on a limb and speculate that even for experienced readers, flip is going to be a bit difficult to parse. But I'll have to come back to that when I have more experience.
- rtpg 10y agoOne flaw I'd point out after working with Purescript a lot is that Haskell's "IO " is very large, to the point of not meaning anything. printing to screen? IO network connections? IO launching the nukes? IO You get this weird effect of having pure code, then _all_ your effectful code inhabiting the same types. Though this helps make you write more pure code, when you do write effectful code, it's not nearly as safe as one might want. Purescript's effects is a nicer granular mechanism.
- hota_mazi 10y agoIt's almost as if programs are useless if they don't perform some IO and therefore, trying to encode this kind of side effects in the type system is theoretically interesting but practically inconvenient.
- johncolanduoni 10y agoYeah, but that's at the uppermost level. Having more granularity at least for functions in libraries between does nothing/does anything makes a lot of sense, considering the observable actions a function can take are often part of the documentation of an API.
- chriswarbo 10y ago> It's almost as if programs are useless if they don't perform some IO You seem to have missed the point. At the moment, a CLI calculator has type "IO ()", a filesystem scanner has type "IO ()", an FTP library has type "IO ()", a random password generator has type "IO ()", etc. It's very convenient that GHC points out when I try to, for example, perform arithmetic on lists, or insert unsanitised strings into templates. It would also be convenient if it points out when my CLI calculator is trying to perform network requests, when my filesystem scanner is trying to generate random numbers, when my random password generator is scanning the filesystem, etc.
- platz 10y agoIn trying to advocate for fine-grained effect systems, i hope Haskell isn't presented as 'unsafe' according to an extremely high standard usually reserved for theorem proving languages. Pure functional programming is fighting an even more basic battle that side-effects should even be separated at all. I feel presenting Haskell's IO as unsafe throws out the baby along with the bathwater. Others have not reached the peaks you look down on.
- Ericson2314 10y agoTools and ecosystem coherence, basically. We have infrastructure technical debt and...factions.
- hota_mazi 10y agoI would add pragmas. People like to say there is just one implementation of Haskell and it's ghc, but there's actually n different ones, with n being the number of combinations of pragmas that exist. Each combination you use in your source is a different version of Haskell.
- harpocrates 10y agoWhile I see how this at first appears to be a problem (when I started with Haskell I sure thought of it as one), it turns out that language-pragma filled code can be mixed with vanilla code too without problem. The pragmas usually just expose more of the inner representation of GHC (I'm thinking things like FlexibleInstances, TypeApplication, RankNTypes and not the pathologically broken and perhaps logically unsound ImpredicativeTypes). So it really is just GHC you are shipping (and not GHC + which extensions are enabled).
- aninhumer 10y agoEh, I think in practice it's more like there's one large language, but you have to enable some of the features with pragmas.
- karma_vaccum123 10y agoBest rant I have read in years: https://www.reddit.com/r/haskell/comments/4sihcv/haskell_the_bad_parts/d5a7344 https://www.reddit.com/r/haskell/comments/4sihcv/haskell_the...
- cies 10y agoPureScript is a language that compiles to JS which is heavily inspired by Haskell, yet fixes some of it's "flaws". Namely it (1) has better record syntax, (2) is employs strict-evaluation instead of lazy-evaluation by default, (3) has a better class hierarchy for "numbers", (4) has a better class hierarchy for control classes[1] (like Monad, Applicative, Functor, etc.). There are more, but to me they are the main improvements. Compared to Haskell, PureScript fixes some of the "flaws". These flaws are mostly different from the flaws mentioned in the article. Maybe one day PureScript can be compiled to native ...<searching internet>... which is already being worked on[2]. [1] https://github.com/purescript/purescript-prelude/tree/master/src/Control https://github.com/purescript/purescript-prelude/tree/master... [2] https://github.com/andyarvanitis/purescript-native https://github.com/andyarvanitis/purescript-native
- misja111 10y agoIs Haskell's default lazy evaluation really a flaw that needs to be fixed? I personally like it, I find that most of the time lazy evaluation is what I need instead of strict.
- cies 10y agoI like Haskell's laziness by default myself. But it turns out that it is hard to reason about for those new to the language, and hard to efficiently cross-compile to a non-lazy language. Perhaps I should rectify that I do not think laziness is a flaw, yet probably a large hurdle to adoption.
- DanWaterworth 10y agoIf you'd like strictness by default, there's a pragma for that https://ghc.haskell.org/trac/ghc/wiki/StrictPragma https://ghc.haskell.org/trac/ghc/wiki/StrictPragma
- taylorfausak 10y agoThis is another flaw that PureScript fixes: No language pragmas.
- SeanDav 10y agoI often wonder what is it that keeps Haskell out of the mainstream as a development language. There seems to have been enormous popular support for Haskell by experts over quite some time, yet relatively newer languages like Golang are coming along and eating Haskell's lunch.
- posterboy 10y agoOne point might be, that Haskell thinks big. Its strengths might not be too noticeable with smaller projects and be problematic because of a steeper learning curve. The inertia is huge. Imperative programming has a lot of momentum, because it reads more or less like text, not maths. A steep learning curve means effectively more power. And that means responsibility. If modularization means separation of concerns, and thus less responsibility, lack of power is largely mitigated, but it puts the responsibility on the s/w-architects. Just like LISP's strength supposedly is revealed when it's the whole OS. And as they say, any involved program will contain an ad-hoc implementation of LISP :) C, eg., also resembled the hardware architecture more closely. With concurrent programming, though, we see more functional influences creep into the staple languages. It's the other way around with Haskell's do notation. Anyway, as a research project, it is rather academic. Therefore it is often not backwards compatible, which is an immediate show stopper and also shows that it's far from finished, due to its bigger goals.
- RubyPinch 10y agoProbably the whole needing to learn an entire part of English that many didn't even know existed before. A language really shouldn't require its language-specific glossary to be mandatory reading, just to understand anyone speaking about it. I could just learn any other language in half the time! from the above comments > "I have this pure function that I want to apply to the inner value of my functor" pure function I know well enough, that is the same for any language, functors though... is that a function object that can be applied to something? then why does it already have a value? I can take terminologies from C, to python, or C#, and feel a-okay, but haskell kinda feels like it went and shut it self away from the world, and its terminology developed differently due to that, I guess.
- avindroth 10y agoI hear NixOS (linux distro based on functional principles) solves the package management problem for Haskell. * https://ocharles.org.uk/blog/posts/2014-02-04-how-i-develop-with-nixos.html https://ocharles.org.uk/blog/posts/2014-02-04-how-i-develop-... * https://www.reddit.com/r/haskell/comments/1vghgw/nixos_a_gnulinux_distribution_based_on_purely https://www.reddit.com/r/haskell/comments/1vghgw/nixos_a_gnu... * https://nixos.org/~eelco/pubs/nixos-jfp-final.pdf https://nixos.org/~eelco/pubs/nixos-jfp-final.pdf * http://fuuzetsu.co.uk/blog/posts/2014-06-28-My-experience-with-NixOS.html http://fuuzetsu.co.uk/blog/posts/2014-06-28-My-experience-wi...
- taylorfausak 10y agoNix (and NixOS) are certainly nice to use with Haskell, but Stack is good. The post even says so: > Stackage solved the consistent set of packages, and Stack made it even easier. I now consider Haskell package management a strength for large projects, not a risk.
- exDM69 10y agoFYI, it's possible to use Nix package manager outside of NixOS. I'm not quite convinced that some of the choices the NixOS distro has made are good (or to my liking) but the package manager seems much better thought out. I was able to quickly install Nix on a not quite up-to-date Linux distro to get my hands on specific versions of some programs that are too big to conveniently build from source. I'm not sure it solves the package management problem for Haskell completely, but it should help managing GHC versions and external dependencies (ie. native libs required by Haskell libs), which cabal/stack aren't great with. Note: I was a bit disappointed that installing Nix required root access to create /nix store. I would have liked to put it in my home directory instead.
- vertex-four 10y agoUnfortunately, because Nix derivations embed full paths to all their dependencies, moving /nix elsewhere means you don't get access to the binary cache and wind up having to build everything from source. If you're happy with that, you can compile Nix manually to put the store in your home directory: https://nixos.org/wiki/How_to_install_nix_in_home_%28on_another_distribution%29#Manual_Installation https://nixos.org/wiki/How_to_install_nix_in_home_%28on_anot...
- drivebyops 10y agoatom (ghcmod + the various haskell pluings) is good enough for me honestly sublimehaskell (hsdev, etc.) was good as well
- spriggan3 10y agoThe overuse of weird operators is just a deal breaker for me. Haskell ideas are good. But I prefer explicit keywords rather than -> <$> and co everywhere. for instance, pattern matching that looks like switch statements would be more readable than lines of |
- icen 10y agoYou can just write something like foo x = case x of pattern1 -> ...
- hellofunk 10y agoRegarding space leaks, the recent GHC version now allows an entire module to be strict, not lazy. Would this prevent space leaks (and perhaps other performance-sensitive problems)?