Created
January 2, 2019 08:32
-
-
Save DonaldKellett/ff67c32aba3dc9115c1767d0064281d5 to your computer and use it in GitHub Desktop.
PureScript by Example - 5.5 Guards - Exercise 1-2 Solutions
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 Guards where | |
import Prelude | |
-- Exercise 1 | |
factorial :: Int -> Int | |
factorial 0 = 1 | |
factorial n = n * factorial (n - 1) | |
-- Exercise 2 | |
choose :: Int -> Int -> Int | |
choose _ 0 = 1 | |
choose n k | |
| n == k = 1 | |
| otherwise = choose (n - 1) k + choose (n - 1) (k - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment