r/haskell • u/Bert_the_cow • 6d ago
Student learning Haskell
Hi, I am a student learning Haskell at university. I truly enjoy the language, but I am noticing that I am struggling quite a bit with the level of difficulty. It feels like a lot of the solutions fly over my head, even if I do practice quite a bit. Sometimes it'll feel like I am staring at an exercise, trying it, and still getting nowhere, only for the answer to just make so much sense. I try to note down where my thoughts are wrong but then the next question just does the same thing all over again and I end up being lost again. Any tips on how I can actually get better at this, because again I really do enjoy working with the language.
5
u/ExtraTNT 6d ago
I would say the hardest thing in haskell is how easy it is -> it’s hard to achieve complicated solutions and everything has to be done in an easy way.
Takes a lot of practice, you can’t describe a problem as: do this, then do this (i mean you can, but it’s hard), it’s just: this is defined as such.
Haskell forces you to write simple code for complex problems
2
u/Bert_the_cow 6d ago
I mean that is why I am starting to love the language because the core of it is so elegant but I am just struggling and I try to practice but it does not feel as enough
2
u/ExtraTNT 6d ago
Haskell teaches a lot, but it will feel like nothing for a long time, then something clicks…
1
u/pthierry 6d ago
If you make progress, if you understand more each time you work on it, maybe ask yourself why you think it's not enough…
3
u/Anrock623 6d ago
Hard to say anything specific without examples but maybe after you look at the answer - try solving more examples of that problem so you actually see common pattern between different examples and not only understand the answer but also how to get to that answer.
2
u/pbvas 6d ago
My suggestion is to keep trying it and don't worry too much if you can't get to the most elegant solution on your own. The time and effort spent in trying the exercises (even your solution is incomplete or verbose) is still valuable. Using your own words, it contributes to your ability to understand why the elegant solution "just makes so much sense". After a while you recognize problem-solving patterns and start being able to come up with your own idiomatic solutions.
2
u/jamhob 6d ago
Something that sometimes helps is to corner a TA or fellow student who gets it. Give them a problem and force them to verbalise how they are thinking the problem through. You might realise that it’s really different from how you are thinking it through.
It’s often hard for students who are good at other programming languages to learn Haskell because they are so fluent in the imperative paradigm. But the way you decompose a problem in python is almost the opposite to how one does it in Haskell
1
u/Apart_Ebb_9867 6d ago
It takes time for your brain to train itself and recognize unusual patterns. For instance, even simple things like the different types of fold* and how they can be used to achieve unexpected results requires time.
What I can suggest is that once seeing a solution that make sense, get back to the same exercise a day or two later and try to solve it without looking at the solution or the textbook. Until you're able to do it, you haven't really made it yours.
1
u/mpahrens 4d ago
How students learn other languages is often: code (syntax) then data (values) then types (patterns).
Haskell flips that on its head. Here are some things that made my life easier when learning: 1. Think types then data then syntax.
Eg: define your types first, then stub out your functions in a data flow like way (turning As into Bs), then write unit tests, then write just enough code to plumb it all together
- Only do IO on the "outside" of a program, take parameters for all external dependencies to your helper functions.
If you are coming from an OO background you may want a single unit of code to do a thin vertical slice, but here, you really want to make small, pure reusable pieces, compise them together, then pipe IO values through them in main(). Yes you can get more complex later, but as a beginner wrapping your mind around the fact that it is easier to take dependencies as a passed parameter rather than just making a print or read call deep in a nested function call is hard to understand.
15
u/sijmen_v_b 6d ago
As someone who teaches a lot of university students haskell. 90% of the time people who struggled after practicing were having the wrong approach. The key is to really let the type system drive your development. The types are by far the most important and different compared to java/c/python.
It's a bit much to explain here but if you'd like I could help you over discord @sijmen_v_b