Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Created January 2, 2019 08:32
Show Gist options
  • Save DonaldKellett/ff67c32aba3dc9115c1767d0064281d5 to your computer and use it in GitHub Desktop.
Save DonaldKellett/ff67c32aba3dc9115c1767d0064281d5 to your computer and use it in GitHub Desktop.
PureScript by Example - 5.5 Guards - Exercise 1-2 Solutions
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