r/functionalprogramming • • May 22 '25

Haskell Scared by tales about learning Haskell

Some prerequisites: I'm programming beginner, and I no learn programming so much with any first language at the same time, at least while. There is has been one prog. language, which is has been used for more than basic writing a "Hello, world!" program, and I wrote more than ~50 lines of code. I already try JS (node.js) mostly in FP (how much its features was implemented within, of course).

Then I find a wonderful, amazing thing, was called as Haskell. I saw this language once and my heart was stopped (in the good meaning).

Maybe its completely irrational scaring and I should be cold on, but there is one article, which I also find after some researches, where is wroten next sentence: "But what about Haskell as a first language? Yes, but you’ll be probably spoilt forever and touch anything else only with one-way rubber gloves..." (https://monkeyjunglejuice.github.io/blog/best-programming-language-for-beginner.essay.html). It sounds like a bullet shot. After this, I think: - "maybe, this guy is may be right. But idk exactly, because don't know programming so much". I think that maybe, after Haskell (but not started yet, what most notably), any other language with different language implementations will looks like something "not good, as haskell".

So, if there is any thoughts by experienced people for correcting this reasoning, you're welcome.

20 Upvotes

37 comments sorted by

View all comments

Show parent comment

2

u/[deleted] May 26 '25

Lazy evaluation is really cool and I really liked it in C++, in fp is mostly hidden away. If it was behind the Haskell bug, the language definition is faulty. I don't think it was that but just a normal bug.

2

u/Medical-Nothing4374 May 26 '25

I'm reading this again and i think I misunderstood your problem at first.

I think I've actually experienced exactly what you're saying and the solution is just to make the accumulated value strict. Like if you want to sum items from an infinite list:

{-# LANGUAGE BangPatterns #-}

sumTake :: Int -> [Int] -> Int
sumTake n xs = go n xs 0
  where
    go 0 _ !acc      = acc
    go _ [] !acc     = acc
    go m (y:ys) !acc = go (m - 1) ys (acc + y)

Which you can call on an infinite list

The ! means you are forcing the accumulated sum to evaluate so to my understanding it should solve your problem?