Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Comparison of tailrec+pattern matching between Haskell and Clojure
(defn max-from-list
"Get the maximum from list using recursion"
[[head & tail]]
(if (empty? tail)
head
(let [max-in-tail (max-from-list tail)]
(if (> head max-in-tail)
head
max-in-tail))))
max' :: [Integer] -> Integer
max' [] = error "max of empty list"
max' [x] = x
max' (x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = max' xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment