Last active
October 22, 2017 16:11
-
-
Save nikivazou/666c41bc9f2f2f62156dac3c407a2022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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