Skip to content

Instantly share code, notes, and snippets.

View rktjmp's full-sized avatar

rktjmp

View GitHub Profile
@animatedlew
animatedlew / patternMatch.hs
Last active February 4, 2023 12:32
Here are some examples of pattern matching in Haskell.
-- Haskell will match starting at the top, until it hits a catchall
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial(n - 1)
-- Haskell is able to match empty lists and x:xs patterns
head' :: [a] -> a
head' [] = error "No head available on empty lists!"
head' (x:_) = x