>>=
->>
λ

haskell.day

Pure. Functional. Elegant.

main :: IO ()
>>= ->>

-- Core Concepts

Types

Type System

Haskell's type system catches errors at compile time, ensuring correctness before your program ever runs. Every expression has a type, and the compiler is your first and most rigorous reviewer. Types are not annotations -- they are the language of your program's logic.

-- Type declarations
data Maybe a = Nothing | Just a fromMaybe :: a -> Maybe a -> a fromMaybe def Nothing = def fromMaybe _ (Just x) = x
id :: a -> a
->>

Monads

Abstraction

Monads provide a structured way to sequence computations with context -- handling side effects, state, and failure in a purely functional way. They are not mystical; they are a design pattern encoded in the type system, enabling composable and predictable programs.

-- Monadic composition
getLine >>= putStrLn do name <- getLine putStrLn ("Hello, " ++ name)
(>>=) :: Monad m => m a -> (a -> m b) -> m b
>>=

Functors

Mapping

Functors let you apply a function over a wrapped value without unwrapping it. They are the foundation of mapping and transformation in Haskell. From lists to IO actions, functors unify the idea of applying functions inside structured contexts.

-- Functor in action
fmap (+1) [1, 2, 3] -- [2, 3, 4] fmap show (Just 42) -- Just "42" (<$>) :: Functor f => (a -> b) -> f a -> f b
fmap :: Functor f => (a -> b) -> f a -> f b
->>

Type Classes

Polymorphism

Type classes define shared behavior across types. Unlike interfaces in other languages, Haskell type classes support default implementations, superclass constraints, and are resolved entirely at compile time -- enabling ad-hoc polymorphism with zero runtime cost.

-- Defining a type class
class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool x /= y = not (x == y)
show :: Show a => a -> String
>>=

Lazy Evaluation

Evaluation

Haskell evaluates expressions only when needed. This enables infinite data structures, efficient memory use, and elegant algorithms. Laziness separates the description of computation from its execution, enabling a declarative style that is both powerful and beautiful.

-- Infinite structures
fibs = 0 : 1 : zipWith (+) fibs (tail fibs) take 10 fibs -- [0,1,1,2,3,5,8,13,21,34] ones = 1 : ones -- infinite list of 1s
take :: Int -> [a] -> [a]
>>= >>= ->>

-- The Beauty of Types

map :: (a -> b) -> [a] -> [b]
>>=
foldr :: (a -> b -> b) -> b -> [a] -> b
->>
filter :: (a -> Bool) -> [a] -> [a]
>>=
concat :: [[a]] -> [a]
->>
traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
>>=
pure :: Applicative f => a -> f a
->>
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
>>=
return :: Monad m => a -> m a

Mathematical elegance, expressed in types.