Created
October 9, 2017 08:15
-
-
Save Shuumatsu/241e8ba80c340574e30919888e2ffb2b 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
module ChurchNumberals where | |
type ChurchNumberals a = (a -> a) -> a -> a | |
one :: ChurchNumberals a | |
one f = f | |
two :: ChurchNumberals a | |
two f = f . f | |
chToInt :: ChurchNumberals Int -> Int | |
chToInt c = c (+ 1) 0 | |
x' = chToInt one | |
y' = chToInt two | |
add' :: ChurchNumberals a -> ChurchNumberals a -> ChurchNumberals a | |
add' x y = \s z -> x s $ y s z | |
multiply' :: ChurchNumberals a -> ChurchNumberals a -> ChurchNumberals a | |
multiply' x y = x . y | |
-- https://courses.edx.org/courses/course-v1:DelftX+FP101x+3T2015/courseware/5240e299c3604e319986d1d8b3459a5a/f615a291386049d7abcee669b5e3d75c/?child=first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment