Last active
May 3, 2018 15:44
-
-
Save epsxy/fbd923df31ecf403b6460b0ba06127ac to your computer and use it in GitHub Desktop.
Some cool haskell tricks
This file contains 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
-- Quick sort | |
quicksort :: Ord a => [a] -> [a] | |
quicksort [] = [] | |
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) | |
where | |
lesser = filter (< p) xs | |
greater = filter (>= p) xs | |
-- Quick sort v2 | |
qsort [] = [] | |
qsort (p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p] | |
-- Unit Testing | |
import Test.HUnit | |
tests = TestList[ | |
TestLabel "should_display_hello_world" should_display_hello_world] | |
should_display_operator = TestCase ( | |
assertEqual | |
"Display Hello World" | |
(show HelloWorld) | |
"Hello Word" | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment