Collatz in Type Level
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 847B

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Collatz Conjecture
  2. Collatz Conjecture (Snowflake / `3n+1`) done in the GHC Type System.
  3. ## Running
  4. in `ghci` load the file:
  5. ```
  6. :load collatz.hs
  7. ```
  8. and run with the following:
  9. ```
  10. :t solution (nil :: X)
  11. ```
  12. where `X` is the church encoding using `S n` and `Z`, ie
  13. `(S (S (S Z)))` is the number `3`
  14. ## Example
  15. ```
  16. *Main> :t solution (nil :: (S (S (S Z))))
  17. solution (nil :: (S (S (S Z))))
  18. :: Cons
  19. (S (S (S Z)))
  20. (Cons
  21. (S (S (S (S (S (S (S (S (S (S Z))))))))))
  22. (Cons
  23. (S (S (S (S (S Z)))))
  24. (Cons
  25. (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S Z))))))))))))))))
  26. (Cons
  27. (S (S (S (S (S (S (S (S Z))))))))
  28. (Cons
  29. (S (S (S (S Z))))
  30. (Cons
  31. (S (S Z))
  32. (Cons
  33. (S Z)
  34. Nil)))))))
  35. ```
  36. which translates to the following list:
  37. ```
  38. [ 3 10 5 16 8 4 2 1 ]
  39. ```