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.
Thorn Avery ed469e5c49 cleanup 4 years ago first commit 4 years ago
collatz.hs cleanup 4 years ago

Collatz Conjecture

Collatz Conjecture (Snowflake / 3n+1) done in the GHC Type System.


in ghci load the file:

:load collatz.hs

and run with the following:

:t solution (nil :: X)

where X is the church encoding using S n and Z, ie

(S (S (S Z))) is the number 3


*Main> :t solution (nil :: (S (S (S Z))))
solution (nil :: (S (S (S Z))))
  :: Cons
       (S (S (S Z)))
       (S (S (S (S (S (S (S (S (S (S Z))))))))))
       (S (S (S (S (S Z)))))
       (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S Z))))))))))))))))
       (S (S (S (S (S (S (S (S Z))))))))
       (S (S (S (S Z))))
       (S (S Z))
       (S Z)

which translates to the following list:

[ 3 10 5 16 8 4 2 1 ]