Skip to content

Instantly share code, notes, and snippets.

@chessai
Created February 26, 2019 15:53
Show Gist options
  • Save chessai/b104c921943f2560a2cf424c589d0c6e to your computer and use it in GitHub Desktop.
Save chessai/b104c921943f2560a2cf424c589d0c6e to your computer and use it in GitHub Desktop.
{-# OPTIONS_GHC -fforce-recomp -ddump-simpl -fno-worker-wrapper -dsuppress-all #-}
module Main (main) where
import System.Environment (getArgs)
main :: IO ()
main = do
[x,y] <- map read <$> getArgs
let f1 = f x A B
f2 = f y B f1
print f2
data T = A | B | C | D | E | F | G
deriving (Show)
{-# NOINLINE n #-}
n :: T -> T
n A = B
n B = C
n _ = A
f :: Int -> T -> T -> T
f sel x y =
-- function large enough to avoid being simply inlined
let j z = n . n . n . n . n . n $ z
in case sel of
-- j is always tailcalled
0 -> j x
_ -> j y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment