Last active
February 1, 2020 06:45
-
-
Save soupi/ee85d03775c21ad2f9270062deeb1b80 to your computer and use it in GitHub Desktop.
Plate.hs src
This file contains hidden or 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
-- stack exec --package uniplate --package criterion -- ghc Plate.hs -O2 -ddump-simpl -dsuppress-all > /tmp/Plate-dump.hs | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE LambdaCase #-} | |
import GHC.Generics | |
import Transform | |
data Expr | |
= Lit Int | |
| Add Expr Expr | |
| Mul Expr Expr | |
| Div Expr Expr | |
| Sub Expr Expr | |
| Neg Expr | |
deriving (Generic) | |
opts :: Expr -> Expr | |
opts = \case | |
Add (Lit 0) e -> e | |
Add e (Lit 0) -> e | |
Mul (Lit 1) e -> e | |
Mul e (Lit 1) -> e | |
Mul (Lit 0) _ -> Lit 0 | |
Mul _ (Lit 0) -> Lit 0 | |
Neg (Neg e) -> e | |
e -> e | |
foo :: Expr | |
foo = Add (Lit 0) (Lit 1) | |
{-# noinline foo #-} | |
main = do | |
pure $ transformBi opts foo | |
Author
soupi
commented
Feb 1, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment