Why does this Haskell code run slower with -O?
This piece of Haskell code runs much slower with -O , but -O should be non-dangerous . Can anyone tell me what happened? If it matters, it is an attempt to solve this problem , and it uses binary search and persistent segment tree: import Control.Monad import Data.Array data Node = Leaf Int -- value | Branch Int Node Node -- sum, left child, right child type NodeArray = Array Int Node -- create an empty node with range [l, r) create :: Int -> Int -> Node create l r | l + 1 == r = Leaf 0 | otherwise = Branch 0 (create l m) (create m r) where m = (l + r) `div` 2 -- Get the sum in range [0, r).