Skip to content

Instantly share code, notes, and snippets.

@exarkun
Last active March 16, 2023 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exarkun/db734e5bb8bf6a4ddbf12549aa61f389 to your computer and use it in GitHub Desktop.
Save exarkun/db734e5bb8bf6a4ddbf12549aa61f389 to your computer and use it in GitHub Desktop.
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