Skip to content

Instantly share code, notes, and snippets.

@rintaun
Last active December 16, 2015 13:49
Show Gist options
  • Save rintaun/5444247 to your computer and use it in GitHub Desktop.
Save rintaun/5444247 to your computer and use it in GitHub Desktop.
let empty selector = selector True True True
let prepend el list = \selector -> selector el list False
let head list = list (\h t e -> h)
let tail list = list (\h t e -> t)
let is_empty list = list (\h t e -> e)
empty = ->(selector) { selector[_, _, true] }
prepend = ->(el, list) { ->(selector) { selector[el, list, false] } }
head = ->(list) { list[->(h, _, _) { h }] }
tail = ->(list) { list[->(_, t, _) { t }] }
is_empty = ->(list) { list[->(_, _, e) { e }] }
list = prepend["asdf", empty]
head[list] # => "asdf"
empty = lambda do |selector|
selector.call _, _, true
end
prepend = lambda do |el, list|
lambda do |selector|
selector.call el, list, false
end
end
head = lambda do |list|
list.call(lambda do |h, _, _|
h
end)
end
tail = lambda do |list|
list.call(lambda do |_, t, _|
t
end)
end
is_empty = lambda do |list|
list.call(lambda do |_, _, e|
e
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment