Permalink
Browse files

Refactored subst function.

  • Loading branch information...
1 parent 1afc640 commit 4f4309262d414229ebb6dc1ee9d58fb0f4afbfaa @luqui committed Jul 6, 2009
Showing with 8 additions and 7 deletions.
  1. +8 −7 experiments/interp-stack/InterpStack/DepthLazyNF.hs
View
15 experiments/interp-stack/InterpStack/DepthLazyNF.hs
@@ -24,14 +24,15 @@ app _ (_ :@ VPrim _) (_ :@ VLam _) = error "Apply primitive to lambda not suppor
app δ l r = δ :@ VApp l r
subst :: (Value a) => Depth -> Depth -> Val a -> Val a -> Val a
-subst δs shiftδ arg (δbody :@ body)
- | δbody <= δs = δbody :@ body
- | VLam λ <- body = δnew :@ VLam (subst δs shiftδ arg λ)
- | VApp l r <- body = app δnew (subst δs shiftδ arg l) (subst δs shiftδ arg r)
- | VVar <- body = if δs+1 == δbody then arg else δnew :@ VVar
- | VPrim v <- body = 0 :@ VPrim v
+subst δs shiftδ arg = go
where
- δnew = δbody + shiftδ
+ go (δbody :@ body) | δbody <= δs = δbody :@ body
+ go (δbody :@ VLam λ) = newδ δbody :@ VLam (go λ)
+ go (δbody :@ VApp l r) = app (newδ δbody) (go l) (go r)
+ go (δbody :@ VVar) = if δs+1 == δbody then arg else (newδ δbody) :@ VVar
+ go (_ :@ VPrim v) = 0 :@ VPrim v
+
+ newδ δbody = δbody + shiftδ
minFree n (t :% u) = plusWith min (minFree n t) (minFree n u)
minFree n (Lam t) = minFree (n+1) t

0 comments on commit 4f43092

Please sign in to comment.