Last active
November 8, 2021 06:27
-
-
Save yzyzsun/3d1fe11aedfdcc2aea4b5ddfbecc94c9 to your computer and use it in GitHub Desktop.
Fixed-point combinators using iso-recursive types
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
newtype Rec a = Fold { unfold :: Rec a -> a } | |
fix :: (a -> a) -> a | |
fix f = (\x -> f (unfold x x)) (Fold (\x -> f (unfold x x))) |
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
newtype Rec a = Fold (Rec a -> a) | |
unfold :: forall a. Rec a -> Rec a -> a | |
unfold (Fold x) = x | |
fix :: forall a b. ((a -> b) -> a -> b) -> a -> b | |
fix f = (\x -> f (\v -> unfold x x v)) (Fold (\x -> f (\v -> unfold x x v))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment