Skip to content

Instantly share code, notes, and snippets.

@exarkun
Last active March 16, 2023 01:15
Embed
What would you like to do?
collatz :: Integer -> Maybe Integer
collatz n
| n < 1 = Nothing
| n == 1 = Just 0
| even n = fmap (+ 1) $ collatz (n `div` 2)
| odd n = fmap (+ 1) $ collatz (3 * n + 1)
Pattern match(es) are non-exhaustive
In an equation for ‘collatz’:
Patterns not matched:
GHC.Num.Integer.IS _
GHC.Num.Integer.IP _
GHC.Num.Integer.IN _
name: collatz-conjecture
version: 1.2.1.4
dependencies:
- base
library:
exposed-modules: CollatzConjecture
source-dirs: src
ghc-options: -Wall
# dependencies:
# - foo # List here the packages you
# - bar # want to use in your solution.
tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- collatz-conjecture
- hspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment