Created
July 24, 2014 16:55
-
-
Save kojiromike/a2286d74b480818e06e5 to your computer and use it in GitHub Desktop.
even function from idris tutorial
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
even : Nat -> Bool | |
even Z = True | |
even (S k) = odd k | |
where | |
odd Z = False | |
odd (S k) = even k |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From http://eb.host.cs.st-andrews.ac.uk/writings/idris-tutorial.pdf This is a good example of the elegance of FP. We define a function
even
that takes a natural number and returns a boolean. If the argument is0
(Z
), we assume the result isTrue
. If the argument is a successor to a natural numberk
, we assume the result isodd k
, whereodd
of0
isFalse
andodd
of a successor to (another)k
iseven k
. So the entire meaning ofeven
andodd
are reduced down to the meaning of even and odd of 0 and its successors.