dependent-type

replicate function for a length-indexed list using GHC.TypeLits and singletons

不打扰是莪最后的温柔 提交于 2020-01-11 07:34:08
问题 I'm trying to write a replicate function for a length-indexed list using the machinery from GHC.TypeLits, singletons, and constraints. The Vect type and signature for replicateVec are given below: data Vect :: Nat -> Type -> Type where VNil :: Vect 0 a VCons :: a -> Vect (n - 1) a -> Vect n a replicateVec :: forall n a. SNat n -> a -> Vect n a How can you write this replicateVec function? I have a version of replicateVec that compiles and type checks, but it appears to go into an infinite

replicate function for a length-indexed list using GHC.TypeLits and singletons

一个人想着一个人 提交于 2020-01-11 07:34:07
问题 I'm trying to write a replicate function for a length-indexed list using the machinery from GHC.TypeLits, singletons, and constraints. The Vect type and signature for replicateVec are given below: data Vect :: Nat -> Type -> Type where VNil :: Vect 0 a VCons :: a -> Vect (n - 1) a -> Vect n a replicateVec :: forall n a. SNat n -> a -> Vect n a How can you write this replicateVec function? I have a version of replicateVec that compiles and type checks, but it appears to go into an infinite

How to define a pair type in Idris that only holds certain combinations of values

此生再无相见时 提交于 2020-01-04 09:59:30
问题 I'm trying to learn about dependent types in Idris by attempting something way out of my depth. Please bear with me if I make any silly mistakes. Given the simple type data Letter = A | B | C | D I would like to define a type LPair that holds a pair of Letter such that only "neighboring" letters can be paired. For example, B can be paired with A or C , but not D or itself. It wraps around, so A and D are treated as neighbors. In practice, given x : Letter and y : Letter , mklpair x y would be

Rewriting with John Major's equality

一笑奈何 提交于 2020-01-04 05:56:08
问题 John Major's equality comes with the following lemma for rewriting: Check JMeq_ind_r. (* JMeq_ind_r : forall (A : Type) (x : A) (P : A -> Prop), P x -> forall y : A, JMeq y x -> P y *) It is easy to generalize it like that: Lemma JMeq_ind2_r : forall (A:Type)(x:A)(P:forall C,C->Prop), P A x -> forall (B:Type)(y:B), @JMeq B y A x -> P B y. Proof. intros. destruct H0. assumption. Qed. However I need something a bit different: Lemma JMeq_ind3_r : forall (A:Type)(x:A*A) (P:forall C,C*C->Prop), P

Self-representation and universes in OTT

老子叫甜甜 提交于 2020-01-02 07:16:09
问题 The question is about Observational Type Theory. Consider this setting: data level : Set where # : ℕ -> level ω : level _⊔_ : level -> level -> level # α ⊔ # β = # (α ⊔ℕ β) _ ⊔ _ = ω _⊔ᵢ_ : level -> level -> level α ⊔ᵢ # 0 = # 0 α ⊔ᵢ β = α ⊔ β mutual Prop = Univ (# 0) Type = Univ ∘ # ∘ suc data Univ : level -> Set where bot : Prop top : Prop nat : Type 0 univ : ∀ α -> Type α σ≡ : ∀ {α β γ} -> α ⊔ β ≡ γ -> (A : Univ α) -> (⟦ A ⟧ -> Univ β) -> Univ γ π≡ : ∀ {α β γ} -> α ⊔ᵢ β ≡ γ -> (A : Univ α)

Unusual Kinds and Data Constructors

醉酒当歌 提交于 2020-01-02 05:39:12
问题 I don't know how I didn't notice this, but data constructors and function definitions alike can't use types with kinds other than * and it's variants * -> * etc., due to (->) 's kind signature, even under -XPolyKinds . Here is the code I have tried: {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} data Nat = S Nat | Z data Foo where Foo :: 'Z -> Foo -- Fails foo :: 'Z -> Int -- Fails foo _ = 1 The error I'm getting is the following: <interactive>:8:12: Expected a type, but ‘Z’ has

Does Perl6 support dependent types?

馋奶兔 提交于 2020-01-01 04:18:12
问题 I was recently looking at the wikipedia page for dependent types, and I was wondering; does Perl 6 actually introduce dependent types? I can't seem to find a reliable source claiming that. It might be obvious to some, but it sure as heck ain't obvious to me. 回答1: Against Ven, in the comments following the Perl 6 answer to the SO question "Is there a language with constrainable types?", wrote "perl6 doesn't have dependant types" and later wrote "dependent type, probably not, ... well, if we

How should the general type of a “lemma” function be understood?

烈酒焚心 提交于 2020-01-01 02:39:10
问题 Perhaps this is a stupid question. Here's a quote from the Hasochism paper: One approach to resolving this issue is to encode lemmas, given by parameterised equations, as Haskell functions. In general, such lemmas may be encoded as functions of type: ∀ x1 ... xn. Natty x1 → ... → Natty xn → ((l ~ r) ⇒ t) → t I thought I understood RankNTypes , but I can't make sense of the last part of this proposition. I'm reading it informally as "given a term which requires l ~ r , return that term". I'm

Singleton types in Haskell

删除回忆录丶 提交于 2019-12-31 09:11:22
问题 As part of doing a survey on various dependently typed formalization techniques, I have ran across a paper advocating the use of singleton types (types with one inhabitant) as a way of supporting dependently typed programming. Acording to this source, in Haskell, there is a separation betwen runtime values and compile-time types that can be blurred when using singleton types, due to the induced type/value isomorphism. My question is: How do singleton types differ from type-classes or from

Could not deduce KnownNat in two existentials with respect to the singletons library

徘徊边缘 提交于 2019-12-29 07:33:10
问题 I was experimenting with the singletons library and I found a case that I don't understand. {-# LANGUAGE GADTs, StandaloneDeriving, RankNTypes, ScopedTypeVariables, FlexibleInstances, KindSignatures, DataKinds, StandaloneDeriving #-} import Data.Singletons.Prelude import Data.Singletons.TypeLits data Foo (a :: Nat) where Foo :: Foo a deriving Show data Thing where Thing :: KnownNat a => Foo a -> Thing deriving instance Show Thing afoo1 :: Foo 1 afoo1 = Foo afoo2 :: Foo 2 afoo2 = Foo athing ::