lambda-calculus

Church lists in Haskell

北战南征 提交于 2019-12-22 01:52:54
问题 I had to implement the haskell map function to work with church lists which are defined as following: type Churchlist t u = (t->u->u)->u->u In lambda calculus, lists are encoded as following: [] := λc. λn. n [1,2,3] := λc. λn. c 1 (c 2 (c 3 n)) The sample solution of this exercise is: mapChurch :: (t->s) -> (Churchlist t u) -> (Churchlist s u) mapChurch f l = \c n -> l (c.f) n I have NO idea how this solution works and I don't know how to create such a function. I have already experience with

Is My Lambda Calculus Grammar Unambiguous?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 00:49:47
问题 I am trying to write a small compiler for a language that handles lambda calculus. Here is the ambiguous definition of the language that I've found: E → ^ v . E | E E | ( E ) | v The symbols ^, ., (, ) and v are tokens. ^ represents lambda and v represents a variable. An expression of the form ^v.E is a function definition where v is the formal parameter of the function and E is its body. If f and g are lambda expressions, then the lambda expression fg represents the application of the

Is it usual for interaction nets to leave piles of redundant fans?

a 夏天 提交于 2019-12-21 03:35:19
问题 I'm compiling lambda calculus terms to interaction nets in order to evaluate them using Lamping's abstract algorithm. In order to test my implementation, I used this church-number division function: div = (λ a b c d . (b (λ e . (e d)) (a (b (λ e f g . (e (λ h . (f h g)))) (λ e . e) (λ e f . (f (c e)))) (b (λ e f . e) (λ e . e) (λ e . e))))) Dividing 4 by 4 (that is, (λ k . (div k k)) (λ f x . (f (f (f (f x))))) ), I get this net: (Sorry for the awful rendering. λ is a lambda, R is root, D is

interpret Parigot's lambda-mu calculus in Haskell

☆樱花仙子☆ 提交于 2019-12-21 01:06:13
问题 One can interpret the lambda calculus in Haskell: data Expr = Var String | Lam String Expr | App Expr Expr data Value a = V a | F (Value a -> Value a) interpret :: [(String, Value a)] -> Expr -> Value a interpret env (Var x) = case lookup x env of Nothing -> error "undefined variable" Just v -> v interpret env (Lam x e) = F (\v -> interpret ((x, v):env) e) interpret env (App e1 e2) = case interpret env e1 of V _ -> error "not a function" F f -> f (interpret env e2) How could the above

Embedding higher kinded types (monads!) into the untyped lambda calculus

狂风中的少年 提交于 2019-12-20 11:09:03
问题 It's possible to encode various types in the untyped lambda calculus through higher order functions. Examples: zero = λfx. x one = λfx. fx two = λfx. f(fx) three = λfx. f(f(fx)) etc true = λtf. t false = λtf. f tuple = λxyb. b x y null = λp. p (λxy. false) I was wondering if any research has gone into embedding other less conventional types. It would be brilliant if there is some theorem which asserts that any type can be embedded. Maybe there are restrictions, for example only types of kind

Calling/applying lambda vs. function call - the syntax in Ruby is different. Why?

一世执手 提交于 2019-12-20 09:27:43
问题 I am kinda new to Ruby and still trying to understand some of the language design principles. IF I've got it right, the lambda expression call in Ruby must be with square braces, while the "regular" function call is with "regular"/round braces. Is there a special reason that the syntax is different? Or, in other words, (why) should the caller be aware whether they call a function or apply a lambda expression? 回答1: Because in Ruby, methods are not lambdas (like, for example, in JavaScript).

Checking understanding of: “Variable” v.s. “Value”, and “function” vs “abstraction”

試著忘記壹切 提交于 2019-12-19 02:59:45
问题 (This question is a follow-up of this one while studying Haskell.) I used to find the notion between "variable" and "value" confusing. Therefore I read about the wiki-page of lambda calculus as well as the previous answer above. I come out with below interpretations. May I confirm whether these are correct? Just want to double confirm because these concept are quite basic but essential to functional programming. Any advice is welcome. Premises from wiki: Lambda Calculus syntax exp → ID | (exp

`or` function in Scheme misbehaving

醉酒当歌 提交于 2019-12-14 03:59:52
问题 I am trying to write an or function in Scheme (define or (lambda (p q) p p q)) If I do (or #t #f) I get #f . What is the problem in what I am doing? I saw λpq.ppq in a video on youTube. 回答1: The correct Lambda Calculus definitions are (define or (lambda (p q) (p p q))) ; (or p q) = {p AND p} OR {{NOT p} AND q} (define xor (lambda (p q) (p (not q) q))) ; (xor p q) = {p AND {NOT q}} OR {{NOT p} AND q} (define not (lambda (t) (lambda (p q) (t q p)))) ; ((not t) p q) = (t q p) (note the parens!).

lambda calculus, normal order, normal form,

你离开我真会死。 提交于 2019-12-14 01:04:13
问题 In lambda calculus, if a term has normal form, normal order reduction strategy will always produce it. I just wonder how to prove the above proposition strictly? 回答1: The result you mention is a corollary of the so called standardization theorem, stating that for any reduction sequence M->N there is another "standard" one between the same terms M and N, where you execute redexes in leftmost outermost order. The proof is not so trivial, and there are several different approaches in the

How to implement iteration of lambda calculus using scheme lisp?

我的未来我决定 提交于 2019-12-11 08:04:38
问题 I'm trying to learn lambda calculus and Scheme Lisp. The tutorial on lambda calculus can be found here http://www.inf.fu-berlin.de/lehre/WS03/alpi/lambda.pdf. The problem I'm facing is I don't know how to properly implement iteration. (define (Y y) (((lambda (x) (y (x x))) (lambda (x) (y (x x)))))) (define (sum r n) ((is_zero n) n0 (n succ (r (pred n))))) (display ((Y sum) n5)) I always get this error: Aborting!: maximum recursion depth exceeded I know the problem is about the evaluation