Created
September 19, 2017 14:07
-
-
Save angerman/92420c4546876bf9f2612187707cf7d4 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 MagicHash, BangPatterns #-} | |
module Main where | |
import GHC.Exts | |
{-# NOINLINE f #-} | |
f :: (Int# -> Float# -> Double# -> Float# -> Double# -> String) -> String | |
f g = g 3# 4.0# 5.0## 6.0# 6.9## ++ " World!" | |
{-# NOINLINE p #-} | |
p :: Int# -> Float# -> Double# -> Float# -> Double# -> String | |
p i j k l m = "Hello" | |
{-# NOINLINE q #-} | |
q :: Int# -> Int# -> Float# -> Double# -> Float# -> Double# -> String | |
q _ i j k l m = "Hello " ++ show (F# l) ++ " " ++ show (D# m) | |
{-# NOINLINE r #-} | |
r :: Int# -> Float# -> Double# -> Float# -> Double# -> String | |
r i = let !(I# z) = length [I# 1# .. I# i] in \j k l m -> p z j k l m | |
-- ghc won't eta-expand around the length, because it has unknown cost | |
main = do | |
putStrLn (f p) -- fast call | |
putStrLn (f r) -- slow call: function but wrong arity | |
let g = last [q 1#] | |
putStrLn (f g) -- slow call: thunk | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE to self: do not pass
-keep-llvm-file
, it will silently force-fllvm
../inplace/bin/ghc-stage1 -fllvm -fforce-recomp T6084.hs -O2 -o T6084-llvm && ./T6084-llvm
[1 of 1] Compiling Main ( T6084.hs, T6084.o )
Linking T6084-llvm ...
Hello World!
Hello World!
Hello 4.0 5.0 World!
../inplace/bin/ghc-stage1 -fasm -fforce-recomp T6084.hs -O2 -o T6084-asm && ./T6084-asm
[1 of 1] Compiling Main ( T6084.hs, T6084.o )
Linking T6084-asm ...
Hello World!
Hello World!
Hello 6.0 6.9 World!