Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So is Haskell not functional? Or an imperative language with some functional features?

    -- ghci> example
    -- Triangular number 1 is 0
    -- Triangular number 2 is 1
    -- Triangular number 3 is 3
    -- Triangular number 4 is 6
    -- Triangular number 5 is 10
    example = runEff $ \io -> evalState 0 $ \st -> do
      for_ [1..5] $ \i -> do
        n <- get st
        let msg = "Triangular number " <> show i <> " is " <> show n
        effIO io (putStrLn msg)
        st += i
    
      where
        st += n = modify st (+ n)
(This is not a trick question. Simon Peyton Jones described Haskell as "the world's finest imperative language" [1], and I agree. This code is written using https://hackage.haskell.org/package/bluefin)

[1] Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell





Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: