Hacker News new | ask | show | jobs
by mikewarot 2019 days ago
I still don't understand the way this breaks down...

How many parameters do S,K,or I take?

If x=11, y=12, z=13 what are S,K? I assume I = 11

1 comments

This is more of a λ-Calculus question (unrelated to combinators, really). But S takes 3, K takes 2, and I takes 1. This isn't strictly correct because S/K/I isn't a function, but rather a chain of lambdas with no free variables (and we get the number of "parameters the function takes" by counting the lambda symbols). See §1 in [1]. In your specific case,

    S 11 12 = 12
    K 11 12 13 = 11 13 (12 13)
    I 11 = 11
Keep in mind that the literals "11," "12," and "13" in λ-Calculus aren't numbers.

[1] https://personal.utdallas.edu/~gupta/courses/apl/lambda.pdf

If I understand this right...

S takes 2 values, and returns 1

K takes 3 values, and returns the 1st, 3rd, and (2nd applied to 3rd)

I returns the value it is given (like a no-op)

> K takes 3 values, and returns the 1st, 3rd, and (2nd applied to 3rd)

Everything applies: so, e.g., when we see something like ABC, we actually omit the parentheses; if we include them, we have (((A)B)C). This can be confusing because applications associate to the left, but lambdas associate to the right[1].

So 11 13 (12 13) is actually (((11)13)((12)13)). In roundabout English, 11 applies to 13 which then applies to the result of 12 applies to 13.

[1] https://www.cs.cmu.edu/~anupamg/251-notes/lambda_calculus.pd...

The impedance mismatch is too hard, given the nature of this medium... thanks for trying to help. Maybe next time?
Look here mate yer over thinking it innit?

In Python:

    S = lambda x: lambda y: lambda z: x(z)(y(z))
    K = lambda x: lambda y: x
    I = lambda x: x
That there is runnable code and with it you can implement numbers, math, logic, etc.

That's all the SKI combinators are: those functions. You apply them to themselves in various patterns and they model numbers and arithmetic and programming languages.

    In [1]: S = lambda x: lambda y: lambda z: x(z)(y(z))

    In [2]: K = lambda x: lambda y: x

    In [3]: I = lambda x: x

    In [4]: K(I)
    Out[4]: <function __main__.<lambda>.<locals>.<lambda>(y)>

    In [5]: _(S) is I
    Out[5]: True

    In [6]: K(I)(S) is I
    Out[6]: True
Hope that helps.
Yes, having code that I can play with did help... but I can't figure out S, no matter what I give it, I always get some sort of error.

TypeError: 'int' object is not callable

I think you're definitely getting it, but you're also trying to see how these combinators are useful or at least usable. That's a bit of a tricky question because as @carapace mentions, you'd need to start combining them in interesting ways to get anything useful out of SKI.