combinatory-logic

Can XOR be expressed using SKI combinators?

那年仲夏 提交于 2020-01-15 03:39:24
问题 I have question about SKI-Combinators. Can XOR (exclusive or) be expressed using S and K combinators only? I have True = Cancel False = (Swap Cancel) where Cancel x y = K x y = x Swap: ff x y = S ff x y = ff y x 回答1: Booleans Your question is a bit unclear on the details, but it seems that what you mean is that you have the following representation of booleans: T := K F := S K This works because it means the following reductions hold: T t e => t F t e => e in other words, b t e can be

SystemT Compiler and dealing with Infinite Types in Haskell

跟風遠走 提交于 2019-12-22 09:20:09
问题 I'm following this blog post: http://semantic-domain.blogspot.com/2012/12/total-functional-programming-in-partial.html It shows a small OCaml compiler program for System T (a simple total functional language). The entire pipeline takes OCaml syntax (via Camlp4 metaprogramming) transforms them to OCaml AST that is translated to SystemT Lambda Calculus (see: module Term ) and then finally SystemT Combinator Calculus (see: module Goedel ). The final step is also wrapped with OCaml

define a form as function name?

江枫思渺然 提交于 2019-12-10 20:38:13
问题 I'd like to know what this code means in Scheme: (define ((K x) y) x) (define (((S x) y) z) ((x z) (y z))) The whole file is here. Is this legal Scheme? Is (K x) a parametrized function, something like generic functions in Java? I looked up the MIT Scheme reference, there seems to be nothing mentioned for definition of this kind. 回答1: Trying it in MIT Scheme works (define ((K x) y) x) ;Value: k ((k 3) 4) ;Value: 3 Apparently, these are the definitions for K and S combinators from a

How to parse string into GADT

浪子不回头ぞ 提交于 2019-12-07 08:46:17
问题 I am trying trying to implement Combinatory Logic in Haskell, and I would like to write to parser for the language. I am having trouble getting a parser to work via Parsec. The basic problem is that I need a way to ensure that the objects returned by the parser are well typed. Does anyone have any creative ideas on how to do this? {-# Language GeneralizedNewtypeDeriving #-} import qualified Data.Map as Map import qualified Text.ParserCombinators.Parsec as P import Text.Parsec.Token (parens)

The type signature of a combinator does not match the type signature of its equivalent Lambda function

ⅰ亾dé卋堺 提交于 2019-12-07 04:17:48
问题 Consider this combinator: S (S K) Apply it to the arguments X Y: S (S K) X Y It contracts to: X Y I converted S (S K) to the corresponding Lambda terms and got this result: (\x y -> x y) I used the Haskell WinGHCi tool to get the type signature of (\x y -> x y) and it returned: (t1 -> t) -> t1 -> t That makes sense to me. Next, I used WinGHCi to get the type signature of s (s k) and it returned: ((t -> t1) -> t) -> (t -> t1) -> t That doesn't make sense to me. Why are the type signatures

SystemT Compiler and dealing with Infinite Types in Haskell

会有一股神秘感。 提交于 2019-12-06 02:42:41
I'm following this blog post: http://semantic-domain.blogspot.com/2012/12/total-functional-programming-in-partial.html It shows a small OCaml compiler program for System T (a simple total functional language) . The entire pipeline takes OCaml syntax (via Camlp4 metaprogramming) transforms them to OCaml AST that is translated to SystemT Lambda Calculus (see: module Term ) and then finally SystemT Combinator Calculus (see: module Goedel ). The final step is also wrapped with OCaml metaprogramming Ast.expr type. I'm attempting to translate it to Haskell without the use of Template Haskell. For

How to parse string into GADT

为君一笑 提交于 2019-12-05 15:52:11
I am trying trying to implement Combinatory Logic in Haskell, and I would like to write to parser for the language. I am having trouble getting a parser to work via Parsec. The basic problem is that I need a way to ensure that the objects returned by the parser are well typed. Does anyone have any creative ideas on how to do this? {-# Language GeneralizedNewtypeDeriving #-} import qualified Data.Map as Map import qualified Text.ParserCombinators.Parsec as P import Text.Parsec.Token (parens) import Text.ParserCombinators.Parsec ((<|>)) import Control.Applicative ((<$>), (<*>), (*>), (<*)) data

The type signature of a combinator does not match the type signature of its equivalent Lambda function

你说的曾经没有我的故事 提交于 2019-12-05 10:42:44
Consider this combinator: S (S K) Apply it to the arguments X Y: S (S K) X Y It contracts to: X Y I converted S (S K) to the corresponding Lambda terms and got this result: (\x y -> x y) I used the Haskell WinGHCi tool to get the type signature of (\x y -> x y) and it returned: (t1 -> t) -> t1 -> t That makes sense to me. Next, I used WinGHCi to get the type signature of s (s k) and it returned: ((t -> t1) -> t) -> (t -> t1) -> t That doesn't make sense to me. Why are the type signatures different? Note: I defined s, k, and i as: s = (\f g x -> f x (g x)) k = (\a x -> a) i = (\f -> f) We start

Equivalent to Ruby&#39;s #tap method in Scala [duplicate]

心已入冬 提交于 2019-11-26 14:50:32
问题 This question already has answers here : how to keep return value when logging in scala (6 answers) Closed 6 years ago . Ruby has a method that allows us to observe a pipeline of values, without modifying the underlying value: # Ruby list.tap{|o| p o}.map{|o| 2*o}.tap{|o| p o} Is there such a method in Scala? I believe this is called a Kestrel Combinator, but can't be sure. 回答1: Here is one implementation on github: https://gist.github.com/akiellor/1308190 Reproducing here: import collection