Week2-Haskell/README.md

44 lines
1.1 KiB
Markdown
Raw Normal View History

2019-07-16 20:28:00 -04:00
# I'm so sorry
Hoon101's Week 2 Assignment in Haskell
> Create a gate that takes a noun, checks if its a cell, and if not, checks if the atom is odd or even
## Running
in `ghci`, load the file:
```
:load week2.hs
```
you can then run the program using the form
`:t solution (nil :: X)`
where `X` is either an atom or a cell, using the following syntax:
`Atom`: Using Church Encoding with `(S n)` and `Z`, ie `(S (S (S Z)))` is the atom `3`
`Cell`: Using `Cons x xs` and `Nil`, ie `(Cons (S Z) (Cons Z Z))` is the cell `[1 [0 0]]`
## Example
```
*Main> :load week2.hs
[1 of 1] Compiling Main ( week2.hs, interpreted )
Ok, modules loaded: Main.
*Main> :t solution (nil :: (S (S (S (S Z)))))
solution (nil :: (S (S (S (S Z)))))
:: IsEvenAtom
*Main> :t solution (nil :: (S (S (S (S (S Z))))))
solution (nil :: (S (S (S (S (S Z))))))
:: IsOddAtom
*Main> :t solution (nil :: (Cons (Cons (S Z) (S (S Z))) (Cons (S (S (S Z))) (S (S (S (S Z)))))))
solution (nil :: (Cons (Cons (S Z) (S (S Z))) (Cons (S (S (S Z))) (S (S (S (S Z)))))))
:: IsCell
```