# curry-howard

来源： https://stackoverflow.com/questions/64394487/if-either-can-be-either-left-or-right-but-not-both-then-why-does-it-correspond

## What type corresponds to a xor b in type theory?

来源： https://stackoverflow.com/questions/64380092/what-type-corresponds-to-a-xor-b-in-type-theory

## De Morgan's Laws in Haskell via the Curry-Howard Correspondence

问题 I implemented three of the four De Morgan's Laws in Haskell: notAandNotB :: (a -> c, b -> c) -> Either a b -> c notAandNotB (f, g) (Left x) = f x notAandNotB (f, g) (Right y) = g y notAorB :: (Either a b -> c) -> (a -> c, b -> c) notAorB f = (f . Left, f . Right) notAorNotB :: Either (a -> c) (b -> c) -> (a, b) -> c notAorNotB (Left f) (x, y) = f x notAorNotB (Right g) (x, y) = g y However, I don't suppose that it's possible to implement the last law (which has two inhabitants): notAandBLeft

## How or is that possible to prove or falsify `forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q.` in Coq?

问题 I want to prove or falsify forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q. in Coq. Here is my approach. Inductive True2 : Prop := | One : True2 | Two : True2. Lemma True_has_one : forall (t0 t1 : True), t0 = t1. Proof. intros. destruct t0. destruct t1. reflexivity. Qed. Lemma not_True2_has_one : (forall (t0 t1 : True2), t0 = t1) -> False. Proof. intros. specialize (H One Two). inversion H. But, inversion H does nothing. I think maybe it's because the coq's proof independence (I'm not a

## Curry's paradox in Haskell?

问题 Curry's paradox (named after the same person as the present programming language) is a construction possible in a faulty logic that allows one to prove anything. I know nothing about logic, but how hard can it be? module Main where import Data.Void import Data.Function data X = X (X -> Void) x :: X x = fix \(X f) -> X f u :: Void u = let (X f) = x in f x main :: IO () main = u `seq` print "Done!" It certainly does loop. (How does GHC know?!) % ghc -XBlockArguments Z.hs && ./Z [1 of 1]

## Dependent Types: How is the dependent pair type analogous to a disjoint union?

问题 I've been studying dependent types and I understand the following: Why universal quantification is represented as a dependent function type. ∀(x:A).B(x) means “for all x of type A there is a value of type B(x) ” . Hence it's represented as a function which when given any value x of type A returns a value of type B(x) . Why existential quantification is represented as a dependent pair type. ∃(x:A).B(x) means “there exists an x of type A for which there is a value of type B(x) ” . Hence it's

## De Morgan's Laws in Haskell via the Curry-Howard Correspondence

I implemented three of the four De Morgan's Laws in Haskell: notAandNotB :: (a -> c, b -> c) -> Either a b -> c notAandNotB (f, g) (Left x) = f x notAandNotB (f, g) (Right y) = g y notAorB :: (Either a b -> c) -> (a -> c, b -> c) notAorB f = (f . Left, f . Right) notAorNotB :: Either (a -> c) (b -> c) -> (a, b) -> c notAorNotB (Left f) (x, y) = f x notAorNotB (Right g) (x, y) = g y However, I don't suppose that it's possible to implement the last law (which has two inhabitants): notAandBLeft :: ((a, b) -> c) -> Either (a -> c) (b -> c) notAandBLeft f = Left (\a -> f (a, ?)) notAandBRight :: (

## What are the most interesting equivalences arising from the Curry-Howard Isomorphism?

问题 I came upon the Curry-Howard Isomorphism relatively late in my programming life, and perhaps this contributes to my being utterly fascinated by it. It implies that for every programming concept there exists a precise analogue in formal logic, and vice versa. Here's a "basic" list of such analogies, off the top of my head: program/definition | proof type/declaration | proposition inhabited type | theorem/lemma function | implication function argument | hypothesis/antecedent function result |

## Dependent Types: How is the dependent pair type analogous to a disjoint union?

I've been studying dependent types and I understand the following: Why universal quantification is represented as a dependent function type. ∀(x:A).B(x) means “for all x of type A there is a value of type B(x) ” . Hence it's represented as a function which when given any value x of type A returns a value of type B(x) . Why existential quantification is represented as a dependent pair type. ∃(x:A).B(x) means “there exists an x of type A for which there is a value of type B(x) ” . Hence it's represented as a pair whose first element is a particular value x of type A and whose second element is a

## What are the most interesting equivalences arising from the Curry-Howard Isomorphism?

I came upon the Curry-Howard Isomorphism relatively late in my programming life, and perhaps this contributes to my being utterly fascinated by it. It implies that for every programming concept there exists a precise analogue in formal logic, and vice versa. Here's a "basic" list of such analogies, off the top of my head: program/definition | proof type/declaration | proposition inhabited type | theorem/lemma function | implication function argument | hypothesis/antecedent function result | conclusion/consequent function application | modus ponens recursion | induction identity function |