Eliminate redundant eager calls of elimLambda

This commit is contained in:
James Eversole 2025-01-20 16:05:06 -06:00 committed by James Eversole
parent b385349197
commit eeaf9e0289

View File

@ -57,17 +57,14 @@ elimLambda = go
| null vs = toSKI v (elimLambda body) | null vs = toSKI v (elimLambda body)
| otherwise = elimLambda (SLambda [v] (SLambda vs body)) | otherwise = elimLambda (SLambda [v] (SLambda vs body))
go (SApp f g) = SApp (elimLambda f) (elimLambda g) go (SApp f g) = SApp (elimLambda f) (elimLambda g)
go (TStem t ) = TStem (elimLambda t)
go (TFork l r ) = TFork (elimLambda l) (elimLambda r)
go (SList x ) = SList (map elimLambda x)
go x = x go x = x
toSKI x (SVar y) toSKI x (SVar y)
| x == y = _I | x == y = _I
| otherwise = SApp _K (SVar y) | otherwise = SApp _K (SVar y)
toSKI x t@(SApp n u) toSKI x t@(SApp n u)
| not (isFree x t) = SApp _K (SApp (elimLambda n) (elimLambda u)) | not (isFree x t) = SApp _K t
| otherwise = SApp (SApp _S (toSKI x (elimLambda n))) (toSKI x (elimLambda u)) | otherwise = SApp (SApp _S (toSKI x n)) (toSKI x u)
toSKI x t toSKI x t
| not (isFree x t) = SApp _K t | not (isFree x t) = SApp _K t
| otherwise = SApp (SApp _S (toSKI x t)) TLeaf | otherwise = SApp (SApp _S (toSKI x t)) TLeaf