Created
April 28, 2013 22:23
-
-
Save hiroshi-maybe/5478661 to your computer and use it in GitHub Desktop.
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
| import Control.Monad.Fix | |
| ------------------------------------------------ | |
| -- fact | |
| -- fact is a fixpoint for lambda_fact | |
| fact n = if n == 0 then 1 else n * fact (n-1) | |
| lambda_fact = (\g n -> if n == 0 then 1 else n * g (n-1)) | |
| -- fixpoint combinator 'fix' "encode" recursion of fact | |
| fixpoint_fact = fix lambda_fact | |
| ------------------------------------------------ | |
| -- filter | |
| filter' f xs = if null xs then [] | |
| else let x = if f (head xs) then [head xs] else [] | |
| in x++ (filter' f $ tail xs) | |
| lambda_filter = (\g f xs -> if null xs then [] | |
| else let x = if f (head xs) then [head xs] else [] | |
| in x++ (g f $ tail xs)) | |
| fixpoint_filter = fix lambda_filter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment