[Haskell-cafe] List as input
leledumbo
leledumbo_cool at yahoo.co.id
Wed Oct 15 02:44:57 EDT 2008
module Main where
import Data.List
-- quicksort of any list
qsort [] = []
qsort (x:xs) = qsort(filter(<x) xs) ++ [x] ++ qsort(filter(>=x) xs)
-- optimized quicksort, uses middle element as pivot
qsortOpt [] = []
qsortOpt x = qsortOpt less ++ [pivot] ++ qsortOpt greater
where
pivot = x !! ((length x) `div` 2)
less = filter (<pivot) (delete pivot x)
greater = filter (>=pivot) (delete pivot x)
main = do
putStr "Enter a list: "
l <- readLn
print (qsortOpt l)
-- end of code
Why do I get
ERROR "qsort.hs":17 - Unresolved top-level overloading
*** Binding : main
*** Outstanding context : (Read b, Show b, Ord b)
?
--
View this message in context: http://www.nabble.com/List-as-input-tp19987726p19987726.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe
mailing list