I was busy with functional programming in Swift 2.1, trying to implement the function the encoding of the / cons pair ( cons = λx λy λf fxy in the untyped lambda calculus ), which I had read could not be done in earlier versions of Swift.
With generics, it looks like
func cons<S,T,U>(x:S,_ y:T) -> ((S,T) -> U) -> U
{
return { (f:((S,T) -> U)) -> U in return f(x,y)}
}
cons(1,2)
//error: cannot invoke 'cons' with an argument list of type '(Int, Int)'
//note: expected an argument list of type '(S, T)'
which does not work, and gives an error that I cannot understand (of course, a list of parameters of type (Int, Int) can correspond to variables of type generic (S, T)?)
, , , , , 2; , 3 Int (Int, Int) → Int, .
- Any (. Type Casting Any AnyObject), .
? ? , cons/car/cdr, , (lambdas).