Converting IO Int to Int

As a general rule you write something like this: do x <- somethingThatReturnsIO somethingElseThatReturnsIO $ pureFunction x There is no way to get the “Int” out of an “IO Int”, except to do something else in the IO Monad. In monad terms, the above code desugars into somethingThatReturnsIO >>= (\x -> somethingElseThatReturnsIO $ pureFunction x) … Read more

Pseudo-quicksort time complexity

This “quicksort” is actually deforested tree sort: http://www.reddit.com/r/programming/comments/2h0j2/real_quicksort_in_haskell data Tree a = Leaf | Node a (Tree a) (Tree a) mkTree [] = Leaf mkTree (x:xs) = Node x (mkTree (filter (<= x) xs)) (mkTree (filter (x <) xs)) Binary tree is unbalanced, so O(N^2) worst-case and O(N*Log N) average-case complexity for building search tree. … Read more