-
-
Save bgamari/484842415e5faf9c02fb 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
xs = [Thing 0 c, Thing 1 c] | |
Pure x >>= f = f x | |
Thing i k >>= f = Thing i (\a -> k a >>= f) | |
----------------------------------------------------- | |
c = \_ -> Pure 2 | |
doTestM :: [Assembler Integer] -> Assembler () | |
doTestM xs | |
= let y = Thing 0 c | |
ys = [Thing 1 c] | |
k = doTestM ys | |
in y >>= (\_ -> k) | |
-- Inline >>= | |
= let k = doTestM ys | |
in Thing 0 (\a -> c a >>= (\_ -> k)) | |
-- Inline >>= | |
= let k = doTestM ys | |
in Thing 0 (\_ -> k) | |
run (doTestM xs) | |
= case doTestM xs of Thing i c -> run (c i) | |
-- Inline `doTestM xs` and pattern match | |
= let k = doTestM ys in run $ (\_ -> k) 0 | |
----------------------------------------------------- | |
lvl4 = \_ -> Pure id | |
doTestA xs | |
= let y = Thing 0 c | |
ys = [Thing 1 c] | |
m = doTestA ys | |
in (y >>= lvl4) >>= (\x1 -> m >>= \x2 -> Pure (x1 x2)) | |
-- Inline >>= | |
= let y = Thing 0 c | |
ys = [Thing 1 c] | |
m = doTestA ys | |
in case y >>= lvl4 of | |
Thing i k -> Thing i (\a -> k a >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) | |
Pure a -> k a >>= (\x1 -> m >>= \x2 -> Pure (x1 x2)) | |
-- Inline >>= | |
= let ys = [Thing 1 c] | |
m = doTestA ys | |
in case Thing 0 (\a -> c a >>= lvl4) of | |
Thing i k -> Thing i (\a -> k a >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) | |
-- Pattern match | |
= let ... | |
in Thing 0 (\a0 -> (\a1 -> c a1 >>= lvl4) a0 >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) | |
-- Pattern match | |
= let ... | |
in Thing 0 (\a0 -> (\a1 -> c a1 >>= lvl4) a0 >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) | |
run (doTestA xs) | |
= case doTestA xs of | |
Thing i c -> run (c i) | |
-- Inline `dotestA xs` and pattern match | |
= let m = doTestA ys | |
in run $ (\a0 -> (\a1 -> c a1 >>= lvl4) a0 >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) 0 | |
-- Apply outer lambda to 0 | |
= let ... in run $ (\a1 -> c a1 >>= lvl4) 0 >>= (\x1 -> m >>= \x2 -> Pure (x1 x2)) | |
-- Inline >>= | |
= let ... in run $ | |
case (\a1 -> c a1 >>= lvl4) 0 in | |
Thing i k -> Thing i (\a2 -> k a2 >>= (\x1 -> m >>= \x2 -> Pure (x1 x2))) | |
Pure a -> m >>= \x2 -> Pure (x1 x2) | |
-- Inline >>= | |
= let ... in run $ | |
case (\_ -> lvl4 2) 0 in | |
Pure a -> (\x1 -> m >>= \x2 -> Pure (x1 x2)) a | |
-- Pattern match | |
= let ... in run $ (\x1 -> m >>= \x2 -> Pure (x1 x2)) id | |
-- Apply lambda | |
= let ... in run $ m >>= \x2 -> Pure (id x2) | |
-- Inline >>=, m | |
= run $ case doTestA xs of | |
Thing i k -> Thing i (\x3 -> k x3 >>= (\x2 -> Pure x2)) | |
Pure a -> Pure a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment