Skip to content

Instantly share code, notes, and snippets.

@epsxy
Last active May 3, 2018 15:44
Show Gist options
  • Save epsxy/fbd923df31ecf403b6460b0ba06127ac to your computer and use it in GitHub Desktop.
Save epsxy/fbd923df31ecf403b6460b0ba06127ac to your computer and use it in GitHub Desktop.
Some cool haskell tricks
-- 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