Haskell Cheat Sheet
Haskell syntax, pure functions, algebraic data types, and lazy evaluation for statically typed functional programming.
2 PagesAdvancedApr 2, 2026
Basic Syntax
Bindings, control flow, and IO.
haskell
main :: IO ()main = do let age = 30 name = "Ada" pi' = 3.14159 if age >= 18 then putStrLn (name ++ " is an adult") else putStrLn (name ++ " is a minor") mapM_ (\i -> putStrLn ("Count: " ++ show i)) [0..4]
Functions & Pattern Matching
Defining functions by matching on structure.
haskell
-- function with type signaturesquare :: Int -> Intsquare x = x * x-- pattern matching on listsdescribe :: [Int] -> Stringdescribe [] = "empty"describe [x] = "one element: " ++ show xdescribe (x:xs) = "head " ++ show x ++ ", rest has " ++ show (length xs)factorial :: Int -> Intfactorial 0 = 1factorial n = n * factorial (n - 1)
Types & Type Classes
Algebraic data types and ad-hoc polymorphism.
haskell
data Shape = Circle Double | Rectangle Double Doublearea :: Shape -> Doublearea (Circle r) = pi * r * rarea (Rectangle w h) = w * hclass Describable a where describe :: a -> Stringinstance Describable Shape where describe (Circle r) = "Circle with radius " ++ show r describe (Rectangle w h) = "Rectangle " ++ show w ++ "x" ++ show h
Core Syntax & Types
Common Haskell notation.
- ::- reads as 'has type', used for type signatures
- ->- function type/arrow, e.g. Int -> Int
- data- defines a new algebraic data type
- Maybe a- Just value or Nothing, avoids null
- Either a b- Left error or Right success value
- ($)- low-precedence function application operator, avoids parens
- (.)- function composition operator
- IO a- type wrapping actions that perform side effects
Pro Tip
Haskell is lazily evaluated by default — use `seq` or strict data types (via `!` bang patterns) when accumulating large sums to avoid building up unevaluated thunks that blow the stack.
Was this cheat sheet helpful?
Explore Topics
#Haskell#HaskellCheatSheet#Programming#Advanced#BasicSyntax#FunctionsPatternMatching#TypesTypeClasses#CoreSyntaxTypes#Functions#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance