Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifesdjeen/9209884 to your computer and use it in GitHub Desktop.
Save ifesdjeen/9209884 to your computer and use it in GitHub Desktop.
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