views:

128

answers:

2

Hi all,

I'm trying to figure out how to express the Y-Combitor in this Finally Tagless EDSL:

class Symantics exp where
    lam :: (exp a -> exp b) -> exp (exp a -> exp b)
    app :: exp (exp a -> exp b) -> exp a -> exp b

    fix :: ...
    fix f = .....

I'm not certain but I think a default implementation of the Y-Combinator should be possible using "lam" and "app".

Anybody know how? My first attempts fail because of the "cannot construct the infinite type" thingy.

Cheers, Günther

+2  A: 

If you introduce let, you can provide a default implementation. But you can't do so with lam and app alone, for the same reason you can't write it directly in Haskell without let. Your target here is an extension of the simply typed lambda calculus, and that term just won't type in it.

sclv
+2  A: 

As sclv points out, you'll need to introduce a primitive fixed point form into the language. Think about how it is defined in Haskell:

fix :: (a -> a) -> a
fix f = let x = f x in x

A suitable 'let' binding form will get you there. A good reference for this kind of foundational stuff is Barendregt chapters 1 and 2, which might be at your library -- though I believe it is out of print (can anyone confirm?). A close second is http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.46.9283

Don Stewart
sclv, Don,thank you very much for your answers, what you have pointed out is far more useful to me even in other circumstances than I had expected.@Don: What would be the title of the book by Barendregt you are referring to? Thanks,Günther
Günther Schmidt
"Barendregt, H. P. The Lambda Calculus: Its Syntax and Semantics. North Holland, Amsterdam (1984).". Quite rare now, but truly a classic, http://www.amazon.com/Lambda-Calculus-Studies-Foundations-Mathematics/dp/0444875085/Really needs to be released open source :/
Don Stewart