Skip to content

Instantly share code, notes, and snippets.

@isterin
Created October 28, 2010 19:41
Show Gist options
  • Save isterin/652169 to your computer and use it in GitHub Desktop.
Save isterin/652169 to your computer and use it in GitHub Desktop.
-- Product function
product' [] = 1
product' (x:xs) =
do putStrLn "testing"
return ((product' xs) * x)
-- quicksort function using where clause
qsort [] = []
qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger
where
smaller = [a | a <- xs, a <= x]
larger = [b | b <- xs, b > x]
-- reverse quicksort function
rqsort [] = []
rqsort (x:xs) = rqsort (rqsort larger) ++ [x] ++ smaller
where
smaller = [a | a <- xs,a <= x]
larger = [b | b <- xs,b > x]
-- quicksort done using filters vs. where clause
qsort' [] = []
qsort' (x:xs) = (filter (< x) xs) ++ [x] ++ qsort' (filter (>= x) xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment