Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scott encoding #11

Open
suhr opened this issue Dec 25, 2021 · 2 comments
Open

Scott encoding #11

suhr opened this issue Dec 25, 2021 · 2 comments

Comments

@suhr
Copy link

suhr commented Dec 25, 2021

It would be great to have a Scott encoding support for numbers and lists, as an alternative to Church encoding.

@ifrh
Copy link

ifrh commented Mar 24, 2022

In reply to #11 (comment)

It would be great to have a Scott encoding support for numbers and lists, as an alternative to Church encoding.

From what I see, there is support for Scott numbers, or am I missing something of your point?

lci/src/.lcirc

Lines 117 to 144 in 2deb0d4

# --- Scott-encoding of numerals --------------------------------------
#
# Note: often Scott encoding is presented as
# 0 = \z.\s.z Succ = \n.\z.\s.s n
# But this has the annoying side-effect that 0 is the same as True,
# so we just inverse the two arguments (so Scott-0 == Church-0).
# '0' = \s.\z.z;
# Succ = \n.\s.\z.s n;
# Pred = \n.n I 0;
# IsZero = \n.n (\x.False) True;
# Add = \n.n
# (\pred.\m.Add pred (\s.\z.s m)) # \s.\z.s m is Succ m
# (\m.m);
# Monus = \n.n
# (\n_pred.\m.m
# (\m_pred.Monus n_pred m_pred)
# n)
# (\m.0);
# Mult = \n.n (\pred.\m.Add m (Mult pred m)) (\m.0);
# Exp = \n.\m.m (\pred.Mult n (Exp n pred)) 1;
# Equal = \n.n
# (\n_pred.\m.m
# (\m_pred.Equal n_pred m_pred) # n,m != 0
# False) # n != 0, m == 0
# IsZero; # n == 0, so check if m == 0

@suhr
Copy link
Author

suhr commented Mar 24, 2022

Oh, cool. Are lists also Scott encoded? Also, does it works for pretty-printing too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants