Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gabe Schoenbach
- -- | A module for learning about ADTs
- module ADT where
- import Prelude
- -- Exercise 3.1
- -- | The collatz function defined with guards and then with if/then/else
- collatz :: Integral n => n -> n
- collatz n
- | n == 1 = 1
- | even n = 1 + collatz (n `div` 2)
- | otherwise = 1 + collatz (3*n + 1)
- collatz' :: Integral n => n -> n
- collatz' n = if n == 1
- then 1
- else if even n
- then 1 + collatz' (n `div` 2)
- else 1 + collatz' (3*n + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement