Skip to content

Instantly share code, notes, and snippets.

@nikivazou
Last active October 22, 2017 16:11
Show Gist options
  • Save nikivazou/666c41bc9f2f2f62156dac3c407a2022 to your computer and use it in GitHub Desktop.
Save nikivazou/666c41bc9f2f2f62156dac3c407a2022 to your computer and use it in GitHub Desktop.
{-# LANGUAGE BangPatterns #-}
module Main where
main :: IO ()
main = putStrLn (show $ foo [1..10000000000])
-- without the bang assoc is not recursed
-- but it is recursed with the ! even with the rewrite Rule
withProof :: a -> () -> a
withProof x !_ = x
foo :: [Int] -> Int
foo xs = head xs `withProof` assoc xs [] []
assoc :: [a] -> [a] -> [a] -> ()
assoc [] _ _ = ()
assoc (x:xs) ys zs = assoc xs ys zs
{-# RULES "assoc/runtime" forall xs ys zs. assoc xs ys zs = () #-}
{-# NOINLINE assoc #-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment