Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typing the Y combinator

http://muaddibspace.blogspot.com/2008/01/type-inference-for-simply-typed-lambda.html is a concise definition of the simply typed lambda calculus in Prolog.

It looks okay, but then he purports to assign a type to the Y combinator... whereas in a very real sense the entire purpose of adding types to lambda calculus is to refuse to assign a type to things like the Y combinator.

Can anyone see exactly where his error or -- more likely -- my misunderstanding is?

like image 365
rwallace Avatar asked Sep 13 '10 17:09

rwallace


People also ask

How does Y Combinator work lambda calculus?

Y combinator In the classical untyped lambda calculus, every function has a fixed point. In functional programming, the Y combinator can be used to formally define recursive functions in a programming language that does not support recursion. This combinator may be used in implementing Curry's paradox.

What is a Combinator in programming?

A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.

How does the Y Combinator work?

Y Combinator interviews and selects two or more batches of companies per year. The companies receive total of $500,000 seed money as well as advice, and connections. The companies receive $125,000 on a post-money safe in return for 7% equity and $375,000 on an uncapped safe with a Most Favored Nation (“MFN”) provision.

What is Z Combinator?

Julia Language Combinators The Y or Z Combinator This combinator takes a function and returns a function that when called with argument x , gets passed itself and x .


1 Answers

The Y combinator in its basic form

Y f = (\x -> f (x x)) (\x -> f (x x))

just cannot be typed using the simple type system proposed in the article.

There are other, much easier but meaningful examples that cannot be typed on that level:

Take e.g.

test f = (f 1, f "Hello")

This obviously works for test (\x -> x) but we cannot give the higher-ranked type that was required here, namely

test :: (∀a . a -> a) -> (Int, String)  

But even in more advanced type systems like the GHCI extensions of Haskell which allow the above, Y is still hard to type.

So, given the possibility of recursion, we can just define and work using the fix combinator

fix f = f (fix f) 

with fix :: (a -> a) -> a

like image 55
Dario Avatar answered Nov 09 '22 20:11

Dario