Created
July 30, 2012 14:52
-
-
Save delbertooo/3207504 to your computer and use it in GitHub Desktop.
thrice
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
tail_cps s k = k (tail s) |
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
*Main> thrice tail "foobar" | |
"bar" |
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
tail_cont :: [a] -> Cont r [a] | |
tail_cont x = return $ tail x | |
thrice_cont :: (a -> Cont r a) -> a -> Cont r a | |
thrice_cont f x = do | |
fx <- f x | |
ffx <- f fx | |
fffx <- f ffx | |
return fffx |
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
*Main> runCont (thrice_cont tail_cont "foobar") print | |
"bar" |
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
thrice_cont' :: (a -> Cont r a) -> a -> Cont r a | |
thrice_cont' f x = f x >>= f >>= f >>= return |
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
thrice_cps :: (o -> (o -> r) -> r) -> o -> (o -> r) -> r | |
thrice_cps f_cps x k = | |
f_cps x $ \fx -> | |
f_cps fx $ \ffx -> | |
f_cps ffx $ \fffx -> | |
k fffx |
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
Main*> thrice_cps tail_cps "foobar" print | |
"bar" |
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
thrice :: (o -> o) -> o -> o | |
thrice f x = f (f (f x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment