14 ms·
What I Wish I Knew When Learning Haskell
- dcl 7y agoGreat timing. I was just pondering what functional programming language I should attempt to learn in all my new downtime.
- Apollidore 7y agoHaskell is fun, but bear in mind that it's followes a purely functional programming paradigm, meaning you either do things the Haskell or you don't do them :). But it's a fun language to learn, and there are lots of free quality ressources on the internet
- marceloabsousa 7y agoWhat do you mean by "either do things the Haskell (way) or you don't do them"? Isn't that the same with every language? I still don't understand why people put all sorts of unfair labels on Haskell. By labelling Haskell with "fun", we almost make it sound like it can't be used in production.
- Drakim 7y agoWhat I think he meant is more like "either do things the functional Haskell way or you don't do them", as in, there is no non-functional fallback or alternative in the language, which some functional languages have.
- kadoban 7y agoThere's escape hatches here and there. If you need imperative code, use IO or ST. If you need to debug output something, Debug.Trace. If you need to temporarily bypass purity there's unsafePerformIO and friends (or they can occasionally be used permanently if you do a lot of analysis I believe). It's a pretty practical language compared to its reputation.
- Koshkin 7y agoActually, someone said, “Haskell is the world’s best imperative programming language.”
- sullyj3 7y agoSomebody said it, but it's glib, and not particularly true. I believe it was a comment on do notation, the bind operation, and programmable semicolons. The customizability is definitely cool, but nobody could possibly argue that imperative programming in Haskell is ergonomic.
- sullyj3 7y agoSure, IO and ST are escape hatches, but they're not escape hatches that beginners struggling with the concept of a higher order function are going to be able to use.
- giantDinosaur 7y agoI imagined it was more in the sense of the 'Have fun implementing Quicksort!' variety, where you're fighting the language constructs, basically, to do what you want.
- tmountain 7y agoHaskell has a huge catalog of libraries you can reach for, so you don’t have to reinvent the wheel. That said, the Haskell way can seem very different than what you see in most languages. As an example, IO—or anything causing a side effect—has to happen in the IO Monad. There are good reasons for this, but it takes some getting used to.
- vkou 7y agoThe parent poster is not lamenting that Haskell lacks a trivial sorting function. They are lamenting that implementing a trivial sorting function in Haskell is difficult.
- tmountain 7y agoI disagree. quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort [a | a <- xs, a <= x] biggerSorted = quicksort [a | a <- xs, a > x] in smallerSorted ++ [x] ++ biggerSorted
- magicalhippo 7y agoNot that I know any Haskell, but wouldn't smallerSorted already include x due to <= operator? edit: also, how is the pivot element selected there?
- zests 7y agoBoth of your questions have the same answer. (x:xs) means x is the first element and xs is the rest.
- lonelappde 7y agoFor 99% of programmers, Haskell can't be used in production.
- yakshaving_jgt 7y agoThis is nonsense.
- gtycomb 7y agoI wish I could give you a thumbs up for speaking plain truth here. Anyway programmers will find out for themselves how best to satisfy their customer need.
- masklinn 7y ago> it's followes a purely functional programming paradigm I'd say that it's one take on that paradigm, the Way of Monads is not the only way to do purely functional, Clean uses uniqueness typing instead. Though it otherwise has rather similar properties to Haskell.
- deleted 7y ago[deleted]
- yeshengm 7y agoI'd say start with some eager functional language such as OCaml without the "object" part. Haskell code is hard to debug cuz you can't rely on good old print. Monad itself is never a silver bullet. Type systems and Composability are the true power of FP IMO.
- willtim 7y agoDebugging declarative code is always hard, whatever the language. Haskell does allow you to use trace expressions which will output values to standard out, see Debug.Trace. This is no reason to avoid arguably the most popular (and state-of-the-art) function language and implementation out there.
- marceloabsousa 7y agoI think we can all agree that debugging languages with lazy evaluation is specially hard. To effectively use Debug.Trace you actually need to add strictness and that can be fundamentally incompatible if you do intend to use the full power of lazy evaluation.
- lonelappde 7y agoDebug.Trace won't solve the space leaks lurking around every corner of your program, and won't shave the hundreds of megabytes to gigabytes of RAM the compiler needs for compiling a non trivial program with dependencies.
- fulafel 7y agoThough The Haskell Way includes the io monad, which is imperative code in practice :)
- Random_ernest 7y agoI tried to learn FP multiple times by learning haskell. Never clicked, tried clojure and I was productive after roughly 2 days.
- lonelappde 7y agoFor the 99%, Haskell's purpose is to teach you what to hate about your working language, not to be a working language. https://blog.plover.com/prog/haskell/what-goes-wrong-2.html https://blog.plover.com/prog/haskell/what-goes-wrong-2.html
- rkangel 7y agoHaskell is very much the deep end of learning functional programming - it's at an extreme end of the spectrum in purity and type system. The language I recommend as a first step to most people is Elixir (or Erlang). It's fairly pure, data is immutable, relies on recursion at the lowest level etc. Good code in Elixir is structure in a similar to good code in a lot of other functional languages (and so teaches good habits), but being dynamically typed is avoids that immediate pain of learning about how to keep the compiler happy.
- dan-robertson 7y agoAs a counterpoint, I picked up (some) haskell pretty quickly. I read a lot of code and didn’t get bogged down reading explanations of what a monad is. I also avoided trying to understand too well what the evaluation semantics of the language were. When I read code, I focused on looking at the type signatures and understanding what they meant, then I would stare at the code and try to work out in my head why those definitions would get those types. I did this at a time when there were lots of “I wrote a program in Haskell. Let me explain how it works” blog posts on this site. I defined some data structures and solved a bunch of project euler problems as practice
- akegalj 7y agoI would second this. My experience is that people get scarred of so much new terms which get introduced in Haskell and that could feel overwhelming. When beginning with Haskell, I would advice to just write code and try to intuitively understand bits, but not get down into unwrapping things or theory much. Stay high level and figure out how things interact as you would do in black box model. Don't open the box, but poke it and see what result you will get (in other words; just write code and do trial and error). When you get comfortable with black-box learning then open the box and look for the details.
- BoiledCabbage 7y agoIf you want to learn a functional language absolutely do not learn Haskell. If you're interested in static functional programming, learn Elm and then F#/OCaml. If you're interested in dynamically typed then learn Clojure or possibly Racket. That's it. Spending time learning Haskell as your first (or even second) fp language is a terrible idea and has done more to slow FP adoption than anything. You can learn Elm literally in a weekend it's so small and well organized (go to their site and follow the tutorial). The concepts you pick up will double the speed you learn any other static FP. F# on .net core is cross platform and can run via a vs code plugin. Plus you have a batteries included full class library of practical needs via dot net. Clojure is very productive, great concepts as well. A bit worse tooling / debuggingqgen you have to drop down to deal with java, but also had batteries included java libs. Racket is probably the most isolated of the above. A scheme dialect and a bit closer to historical scheme and Lisp. Don't learn Haskell it's a horrible use of time as a first language. You get 80% of the value in the above languages in somewhere between 1/10 to 1/4th the effort (depending on which lang you choose), and have learned a more practical language, and will actually learn that lang plus Haskell faster than if you had started in Haskell.
- hvs 7y agoAgreed. Haskell is masters class in functional programming that is generally more interested in pushing theory forward (not necessarily a bad thing). If you are a .NET developer, F# is a wonderful language (based on OCaml) that allows you to ease in to FP since it supports functional, oop, and procedural programming. Plus, you have the whole .NET ecosystem as well. You can become very productive, very quickly.
- agentultra 7y agoA counter point: Haskell is pushing for practical applications of pure, statically typed lazy functional programming. There is plenty of real-world Haskell code in production systems by industrial users. The research is on practical applications.
- outlace 7y agoI’ve tried learning Haskell once or twice and it didn’t really click. However, I’m know knee deep in learning Lean, which is a dependently typed functional language that is also a theorem prover and it’s been a much easier ride. It’s not any less complex than Haskell but learning FP by essentially doing mathematics has made it a lot easier for some reason.
- StreamBright 7y agoI like to think that ML languages, in general, are good to start to learn FP with. SML by Dan Grossman is a great resource because it explains the concepts very well. Anything that you learn after will be easier, does not matter if you go for Haskell or F# later. https://www.youtube.com/watch?v=a1fkhDjCHB8&list=PL-eVNDa9MNJczU4ZjhJDT8rIcCa12DyAx https://www.youtube.com/watch?v=a1fkhDjCHB8&list=PL-eVNDa9MN...
- jlevers 7y agoI see a lot of people below saying to chose a functional language other than Haskell. As someone who's currently learning Haskell, I'm finding it _incredibly_ interesting...but I've heard that many of the free online resources don't lay the necessary foundation for learning the more advanced concepts. I'm 6 chapters into Haskell Programming from First Principles [0], and I highly recommend it. [0] https://haskellbook.com/ https://haskellbook.com/
- Iceland_jack 7y agoHaskell is definitely interesting, there is so much to explore and the community is eager
- Iceland_jack 7y agoJust learn Haskell
- CJefferson 7y agoI feel this might have grown beyond its title. Picking the point where I gave up, giving me a list of 7 vscode plugins, without any guidance as to which are more mature, doesnt feel like a thing anyone would wish to know before they start.
- quchen 7y agoI'm pretty sure this (evolving) article has been around well before VSCode's initial release.
- ninkendo 7y agoIs there maybe an article somebody can actually stand a chance of reading end to end? I think GP is right, there’s not a chance somebody who’s actually new to Haskell would find this useful as a true “things I wish I knew” article. It’s more of a complete reference to the entire language. To me at least, “things I wish I knew” implies it’s some sort of companion to a real language guide/tutorial/book, not a replacement for one.
- CJefferson 7y agoI'm sure you are right. That is just picking at one thing I will admit, but I do use vscode, so when I saw a section about how to best use haskell in vscode i was interested. I'm not interested enough, or as a beginner qualified, to evaluate 7 options.
- hopia 7y agoThe IDE problem is still a major pain in Haskell. However, for now there are just I think 2 main options to choose from, and it's fairly straightforward. Still, not everything works as expected yet. We've come a really long way in just the past 3 years with IDE stuff. I suggest you give it another try if you're still interested in diving into Haskell.
- pjmlp 7y agoWell Leksah seems to still be an option.
- eska 7y agoNot what I expected. Seems to be more of a primer/tutorial.
- kmorgh 7y agoI like this reference style of documentation, it tries to give a full overview of everything there is. Which is usually what I'm looking for. The sections are also concise.
- TazeTSchnitzel 7y agoWhat's up with the formatting on this page? In Firefox for iOS (same rendering engine as mobile Safari), all lines but the first one in code listings have 4-character indents, and lines use a larger-than-normal font size seemingly at random.
- The_rationalist 7y agoIt might have to do with the fact that webkit is mostly a deprecated browser?
- recursive 7y ago1. Firefox doesn't use webkit. 2. Webkit isn't deprecated. 3. Webkit isn't a browser.
- TazeTSchnitzel 7y agoFirefox for iOS does use WebKit.
- lonelappde 7y agoThat's what mobile Firefox does to most of the web.
- TazeTSchnitzel 7y agoNot in my experience.
- hopia 7y agoI find myself coming back to this for various stuff all the time. It's a great reference that touches basically everything important for writing real apps with Haskell.
- merricksb 7y agoEarlier discussions: https://news.ycombinator.com/item?id=5546679 https://news.ycombinator.com/item?id=5546679 (2013) https://news.ycombinator.com/item?id=6868303 https://news.ycombinator.com/item?id=6868303 (2013) https://news.ycombinator.com/item?id=7637278 https://news.ycombinator.com/item?id=7637278 (2014) https://news.ycombinator.com/item?id=10209249 https://news.ycombinator.com/item?id=10209249 (2015)
- dang 7y agohttps://news.ycombinator.com/item?id=14226310 https://news.ycombinator.com/item?id=14226310 (2017) https://news.ycombinator.com/item?id=7904987 https://news.ycombinator.com/item?id=7904987 (2014)
- eklavya 7y agoReally just learn it. It's a pity I don't use Haskell at work and yet learning Haskell was the single most bang for buck exercise I have ever done. "Parallel and Concurrent Programming in Haskell" is the best resource I have ever read on parallel and concurrent programming concepts. Every programmer should learn this language even if they never plan/get to use it.
- efnx 7y agoAgreed. The concepts are very useful and applicable elsewhere.
- mikorym 7y agoIf I am not mistaken, Dijkstra advocated for Haskell to be used as a language of instruction at universities. There is an essay somewhere online about it. What I could find is this: [1]. Edit: Indeed, the PDF that is linked to in [1] looks like a scan of the original. [2] [1] https://chrisdone.com/posts/dijkstra-haskell-java/ https://chrisdone.com/posts/dijkstra-haskell-java/ [2] http://www.cs.utexas.edu/users/EWD/OtherDocs/To%20the%20Budget%20Council%20concerning%20Haskell.pdf http://www.cs.utexas.edu/users/EWD/OtherDocs/To%20the%20Budg...
- m4lvin 7y agoThank you for mentioning, finding and linking to this!
- lonelappde 7y agoNote that Dijkstra recommendes Haskell over Java because Haskell is arcane and mathematical, which is good for learning computer science, not because it's good for writing software.
- random314 7y agoYour paraphrasing of "novel" as "arcane" is in bad faith. It is also self evident that djikstra believes that learning computer science is good for writing software.
- frankmcsherry 7y agoHaskell.
- deleted 7y ago[deleted]
- w3mmpp 7y agoAh, Haskell, the language I wish used s-expressions...
- lonelappde 7y agohttps://www.reddit.com/r/haskell/comments/2u5gac/haskell_with_sexpression_syntax https://www.reddit.com/r/haskell/comments/2u5gac/haskell_wit...
- anaphor 7y agoIn the section on "Boolean Blindness", I find the example a bit confusing. I would expect `isNotJust (Just foo)` to equal `False`, not `True`, and vice versa `isNotJust Nothing` to equal `True`. The point has some validity (that you should try to encode data into the types if you can), but the example makes no sense in my opinion. http://dev.stephendiehl.com/hask/#boolean-blindness http://dev.stephendiehl.com/hask/#boolean-blindness
- runaway 7y agoI thought that was the point of the section- that you may be able to tell something is wrong with the example, but the compiler can't. Thus by programming in that fashion you're not taking advantage of the power of the compiler. The improved way below where the Just a is unwrapped with a case allows the compiler to see whether or not x is valid.
- anaphor 7y agoAh ok, that wasn't really clear to me, but that makes way more sense. Clearly I hadn't had any coffee when I read it earlier.
- lonelappde 7y agoThat's what these parts were going for: > Is there anything wrong with the definitions and below > and why is this not caught in the type system? And > ??? on the line you flagged as a bug.
- shahbaby 7y agoA few years ago I accidentally deleted my entire Haskell assignment about 1 day before it was due. Within a few hours I rebuilt it from scratch. That's when I realized the power of functional programming. There's no way I have been able to recover that quickly if I had used an imperative programming language. Since that experience I've tried to follow a functional programming style whenever I can. I've realized that every variable is another state which adds to the complexity of the code.
- UncleMeat 7y agoBut it was a programming assignment. Building a thing fast is, outside of very few situations, not a thing to optimize for. Building something to be maintained and evolved over time by non rockstars is far far more important, IMO. Perl is great for ripping through some script quickly but it has problems for long term maintenance.
- yakshaving_jgt 7y agoBuilding a thing fast is absolutely something to optimise for in business. Time is money.
- shahbaby 7y agoActually outside of a programming assignment, I think maintenance rather than speed is precisely why a company would want a functional code base. How much time is wasted on debugging? Functional programming forces you to deal with your bugs at a much earlier point of development. It also forces you to avoid some bad practices just to meet a deadline. And since you're re-using so many component, you spend much less time with boiler plate code.
- sullyj3 7y agoIt's definitely possible to write "boring Haskell". getting fancy is more of a cultural tendency than a necessity when building things with Haskell. https://www.snoyman.com/blog/2019/11/boring-haskell-manifesto https://www.snoyman.com/blog/2019/11/boring-haskell-manifest...
- 7y ago
- joeblow21 7y agoPython?
- harry8 7y agoIf you're thinking of learning Haskell you should consider the software written in haskell as an indicator of, well, something. List all the programs useful for something other than programming a computer written in haskell: Xmonad window manager Git annexe Pandoc What else, let's get the full list. Exclude anything that we can't directly see or use. I say, yes! Learn Haskell! Just don't expect to write any useful programs because they're pretty rare for people to have written when they've doesn't time learning Haskell. It is great fun. Do it!
- Ericson2314 7y agoAnd how many programmers are paid to write anything anyone has heard of? And how many new well-known not-de elopement-related tools have been written in the last few years?
- yakshaving_jgt 7y agoLook at all these hundreds of companies who use Haskell to write apparently useless software. https://haskellcosm.com/ https://haskellcosm.com/
- harry8 7y agoLook at the thousands of people who learned Haskell and then also felt inspired to write a monad tutorial and publish it on the internet. Your search engine will help to see just how many there are. Contrast with the number of useful applications you can actually install and run that are for some purpose that is not programming. In fact there are more Haskell textbooks you can read than haskell programs you can install (excluding programs for programming - because that's some pyramid scheme vibe there). This tells us something, I didn't even suggest what it tells us. What it suggests to you is what you thought of. And fwiw imho pandoc is extremely useful! And Haskell is great fun and worth your time to learn! What have you written in haskell that we can use?
- yakshaving_jgt 7y ago> What have you written in haskell that we can use? My three commercial Haskell projects are detailed here[0]. [0]: https://jezenthomas.com/projects/ https://jezenthomas.com/projects/
- privethedge 7y agoFor those who really want to blow their mind, I suggest learning Coq instead https://softwarefoundations.cis.upenn.edu/ https://softwarefoundations.cis.upenn.edu/
- spopejoy 7y agoIt's really aggravating that HN goes against it's own culture so thoroughly when it comes to Haskell. We're supposed to comment on what TFA says, not lick our wounds about how Haskell wasn't what we wanted it to be. f you can't contribute to the thrust of TFA how about creating space to listen to people who actually know what they're talking about? Every single piece of hackneyed received wisdom and FUD in here can be easily countered if you talk to somebody with actual production Haskell experience. Speaking for myself: - I run a startup that has production applications making money for 4 years now written entirely in Haskell with 6 devs doing nothing but Haskell (as well as engineers working in JS and our own language, Pact, yes, written in Haskell). - When we need more bandwidth, we work with an all-Haskell consultancy that itself has no trouble finding work and is very successful in their own right. - Before that, I built a group at a major bank writing Haskell code and getting it out in production, and outperforming Java apps. - The tired "eww static types aren't for real business" is opinions masquerading as "facts". If you are a half-decent engineer in ANY language you can make your code refactorable for changing requirements. Whining that types makes that harder just shows your own limitations. Any decent programmer working in a strongly-typed system leverages types to make code _more_ refactorable in _less_ time with _fewer_ bugs. But hey these are just our anecdata too. Here's what I'm not doing: spreading FUD about Python or Clojure or JS, I'm too busy loving what I do. - From a hiring perspective, Haskell programmers as a group offer an immense strategic advantage, and it's mainly _because_ they had to learn Haskell on the weekend and it wasn't handed to them. That shows passion and grit. I've built two teams from scratch now in totally different circumstances and it is simply breezy to find a wide variety of experience levels to craft a team from; they are by far the best teams I have ever worked with, with zero duds. The community is strong and excellent and helps each other out as far as job hunting goes. Don't blame Haskell if it didn't stick, don't hate on Haskell if you find it intimidating or pointless. If anything, you should be grateful that there is a language that is actually different enough to attract a different kind of programmer, lord knows it's why I'm here: after having jobs in Java, C++, Perl, Ruby, JS, Visual Basic, Hypercard, you name it, it was nice to see that there's a different way to do things. It's really fun, there's always more to learn (not true of every language btw), and finally, it kicks serious ass on the performance side (as GC/runtime languages go).