Skip to content

Instantly share code, notes, and snippets.

@yihuang
Created March 31, 2012 08:51
Show Gist options
  • Save yihuang/2260987 to your computer and use it in GitHub Desktop.
Save yihuang/2260987 to your computer and use it in GitHub Desktop.
crazy ghc optimization
module Test (test) where
test :: [Int] -> Bool
test l = all (==(-1)) $ zipWith (-) l (tail l)
{-
ghc -ddump-simpl -O ghc-optimization.hs
after clean up:
test1 :: Int -> Int -> Bool
test1 a b = (a-b) == (-1)
test :: [Int] -> Bool
test l = GHC.List.foldr2 test1 True l (case l of
[] -> GHC.List.tail1
(x:xs) -> xs
)
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment