Last active
August 29, 2015 13:56
-
-
Save ifesdjeen/9209884 to your computer and use it in GitHub Desktop.
Comparison of tailrec+pattern matching between Haskell and Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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