Last active
April 3, 2018 20:39
-
-
Save tmiller/2b3228b0d9a1e798662f527425c814d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule TenderList do | |
def cons(x, y), do: fn(m) -> m.(x,y) end | |
def car(cell), do: cell.(fn(x, _) -> x end) | |
def cdr(cell), do: cell.(fn(_, y) -> y end) | |
def test do | |
list = cons(1, cons(2, cons(3, 4))) | |
IO.puts car(list) | |
IO.puts car(cdr(list)) | |
IO.puts car(cdr(cdr(list))) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://repl.it/@tmiller/Tenderlang | |
cons x y = \m -> m x y | |
car cell = cell $ \x _ -> x | |
cdr cell = cell $ \_ y -> y | |
main = do | |
putStrLn $ show $ car list | |
putStrLn $ show $ car $ cdr list | |
putStrLn $ show $ car $ cdr $ cdr list | |
where | |
list = cons 1 $ cons 2 $ cons 3 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment