Migrating function from LET to WHERE in Haskell
haskell
Solution
You need to match the indentation of the expressions in a `where` clause, e.g.
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted
where smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
or
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted
where
smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
Problem
In order to improve my Haskell skills I decided to go through some example code and try to rewrite in a different way. Here is the initial function: ``` quicksort :: (Ord a) => [a] -> [a] quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort [a | a <- xs, a <= x] biggerSorted = quicksort [a | a <- xs, a > x] in smallerSorted ++ [x] ++ biggerSorted ``` Here is the migrated function: ``` quicksort :: (Ord a) => [a] -> [a] quicksort [] = [] quicksort (x:xs) = smallerSorted ++ [x] ++ biggerSorted where smallerSorted = quicksort [a | a <- xs, a <= x] biggerSorted = quicksort [a | a <- xs, a > x] ``` However looks to me that it is not working. Is there something wrong? Can functions using LET ported to WHERE? This is my error output: ``` /Users/graph/Documents/Uni/Haskell/hey.hs:43:5: parse error on input `biggerSorted' Failed, modules loaded: none. ``` Many thanks!