The VikiD Truth

Knowledge base / Computing / Functional programming

Read This! | Algorithms | AssemblyLanguage | BASH | C-Programmming | Computer Security | Databases | Emacs | Exploitation | Functional Programming | Firewalls | Git | Haskell | Javascipt | Julia | Social Engineering | Picolisp | Pharo Smalltalk | Linux | Python | Operating Systems | Machine Learning | Metasploit | Open Data Science | Networking | Machine Learning |Scheme | Unity | vim | Web Development

Haskell

Here is the truth about Haskell: it is the language where the type checker is not a nag – it is a collaborator that writes half the program with you. Once you accept that purity and laziness are features, a lot of software architecture lessons fall out for free.

What it is, in plain words

Haskell is a purely functional, statically typed, lazily evaluated language, born from academic language research in the late 1980s and still evolving (GHC is the main compiler; Haskell 2010 is the standard most people mean, with GHC extensions widely used). Its pillars:

Why it matters

Even if you never ship Haskell, a month with it permanently changes how you write Python, Rust, JavaScript and Lisp. Ideas that felt academic – pure functions, Maybe/Optional, parser combinators, software transactional memory – showed up in industry through Haskell’s influence. PureScript is its cousin on JavaScript; Rust’s traits owe a debt; Elm took a simpler slice to the browser.

An everyday analogy: a proof assistant for everyday code

Writing Haskell feels less like giving orders and more like constructing a proof that your program makes sense. The compiler is the examiner. Failures are usually type errors that point at the real mistake – not a crash at 3 a.m. in production.

flowchart LR
  S[source] --> G[GHC]
  G --> T[type check]
  T --> C[core → STG → LLVM/Cmm]
  C --> B[binary]
  T -. error .-> S

A hands-on example

sudo xbps-install -S ghc cabal-install   # or use ghcup
ghci                                     # the REPL
-- sum of squares of evens, the Haskell way
sumOfEvenSquares :: Int -> Int
sumOfEvenSquares n =
  sum [x * x | x <- [1..n], even x]

-- Algebraic data type + pattern match
data Shape = Circle Double | Rect Double Double
  deriving (Show, Eq)

area :: Shape -> Double
area (Circle r) = pi * r * r
area (Rect w h) = w * h

-- Maybe instead of null
safeDiv :: Double -> Double -> Maybe Double
safeDiv _ 0 = Nothing
safeDiv x y = Just (x / y)

-- fmap / Functor – apply a function under the Maybe
result :: Maybe Double
result = (*2) <$> safeDiv 10 4          -- Just 5.0

-- Do-notation for IO (effects are explicit)
main :: IO ()
main = do
  putStrLn $ show $ sumOfEvenSquares 10
  print $ area (Rect 3 4)
  print result
cabal init -n && cabal run

A taste of the ecosystem: Cabal / Stack for projects, Hackage for packages, hls (Haskell Language Server) for editor support. Popular libraries: aeson (JSON), servant or yesod (web), containers and unordered-containers, lens (optional, powerful).

A tiny project shape

mkdir hello-hs && cd hello-hs
cabal init -n --is-executable
# edit app/Main.hs, then:
cabal build
cabal run
cabal test

GHC2021 (a bundle of widely used extensions) is a sensible default for new code. Add dependencies in the .cabal file and let Cabal fetch them. For reproducible builds across machines, commit cabal.project.freeze or use Stack’s resolver pins.

Common misconceptions

Connections

Getting Started

  1. Haskell Kata
  2. Fpcomplete Get Started
  3. Fpcomplete How to Play
  4. Fpcomplete Stack Building
  5. Fpcomplete - Learn
  6. Haskell Stack Docs
  7. GHCUp
  8. Learn You a Haskell
  9. Cabal Docs
  10. Archlinux Haskell Wiki

Last edited · 4 revisions

Tags: #Computing