curry-howard

Can GADTs be used to prove type inequalities in GHC?

喜欢而已 提交于 2019-11-30 06:38:55
So, in my ongoing attempts to half-understand Curry-Howard through small Haskell exercises, I've gotten stuck at this point: {-# LANGUAGE GADTs #-} import Data.Void type Not a = a -> Void -- | The type of type equality proofs, which can only be instantiated if a = b. data Equal a b where Refl :: Equal a a -- | Derive a contradiction from a putative proof of @Equal Int Char@. intIsNotChar :: Not (Equal Int Char) intIsNotChar intIsChar = ??? Clearly the type Equal Int Char has no (non-bottom) inhabitants, and thus semantically there ought to be an absurdEquality :: Equal Int Char -> a function..

Can GADTs be used to prove type inequalities in GHC?

非 Y 不嫁゛ 提交于 2019-11-29 05:47:25
问题 So, in my ongoing attempts to half-understand Curry-Howard through small Haskell exercises, I've gotten stuck at this point: {-# LANGUAGE GADTs #-} import Data.Void type Not a = a -> Void -- | The type of type equality proofs, which can only be instantiated if a = b. data Equal a b where Refl :: Equal a a -- | Derive a contradiction from a putative proof of @Equal Int Char@. intIsNotChar :: Not (Equal Int Char) intIsNotChar intIsChar = ??? Clearly the type Equal Int Char has no (non-bottom)

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

最后都变了- 提交于 2019-11-28 11:18:32
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 native English speaker, and I don't know the exact words, please forgive my ignorance), and coq makes it

Constructing efficient monad instances on `Set` (and other containers with constraints) using the continuation monad

主宰稳场 提交于 2019-11-28 05:48:14
Set , similarly to [] has a perfectly defined monadic operations. The problem is that they require that the values satisfy Ord constraint, and so it's impossible to define return and >>= without any constraints. The same problem applies to many other data structures that require some kind of constraints on possible values. The standard trick (suggested to me in a haskell-cafe post ) is to wrap Set into the continuation monad. ContT doesn't care if the underlying type functor has any constraints. The constraints become only needed when wrapping/unwrapping Set s into/from continuations: import

What's the absurd function in Data.Void useful for?

和自甴很熟 提交于 2019-11-27 17:11:47
The absurd function in Data.Void has the following signature, where Void is the logically uninhabited type exported by that package: -- | Since 'Void' values logically don't exist, this witnesses the logical -- reasoning tool of \"ex falso quodlibet\". absurd :: Void -> a I do know enough logic to get the documentation's remark that this corresponds, by the propositions-as-types correspondence, to the valid formula ⊥ → a . What I'm puzzled and curious about is: in what sort of practical programming problems is this function useful? I'm thinking that perhaps it's useful in some cases as a type

Constructing efficient monad instances on `Set` (and other containers with constraints) using the continuation monad

主宰稳场 提交于 2019-11-27 01:09:30
问题 Set , similarly to [] has a perfectly defined monadic operations. The problem is that they require that the values satisfy Ord constraint, and so it's impossible to define return and >>= without any constraints. The same problem applies to many other data structures that require some kind of constraints on possible values. The standard trick (suggested to me in a haskell-cafe post) is to wrap Set into the continuation monad. ContT doesn't care if the underlying type functor has any

What's the absurd function in Data.Void useful for?

做~自己de王妃 提交于 2019-11-26 18:53:09
问题 The absurd function in Data.Void has the following signature, where Void is the logically uninhabited type exported by that package: -- | Since 'Void' values logically don't exist, this witnesses the logical -- reasoning tool of \"ex falso quodlibet\". absurd :: Void -> a I do know enough logic to get the documentation's remark that this corresponds, by the propositions-as-types correspondence, to the valid formula ⊥ → a . What I'm puzzled and curious about is: in what sort of practical