gadt

Total real-time persistent queues

寵の児 提交于 2019-11-27 17:50:07
问题 Okasaki describes persistent real-time queues which can be realized in Haskell using the type data Queue a = forall x . Queue { front :: [a] , rear :: [a] , schedule :: [x] } where incremental rotations maintain the invariant length schedule = length front - length rear More details If you're familiar with the queues involved, you can skip this section. The rotation function looks like rotate :: [a] -> [a] -> [a] -> [a] rotate [] (y : _) a = y : a rotate (x : xs) (y : ys) a = x : rotate xs ys

Parametrized Inductive Types in Agda

泄露秘密 提交于 2019-11-27 12:25:07
问题 I'm just reading Dependent Types at Work. In the introduction to parametrised types, the author mentions that in this declaration data List (A : Set) : Set where [] : List A _::_ : A → List A → List A the type of List is Set → Set and that A becomes implicit argument to both constructors, ie. [] : {A : Set} → List A _::_ : {A : Set} → A → List A → List A Well, I tried to rewrite it a bit differently data List : Set → Set where [] : {A : Set} → List A _::_ : {A : Set} → A → List A → List A

Creating GADT expression in OCaml

╄→гoц情女王★ 提交于 2019-11-27 06:20:06
问题 There is my toy GADT expression: type _ expr = | Num : int -> int expr | Add : int expr * int expr -> int expr | Sub : int expr * int expr -> int expr | Mul : int expr * int expr -> int expr | Div : int expr * int expr -> int expr | Lt : int expr * int expr -> bool expr | Gt : int expr * int expr -> bool expr | And : bool expr * bool expr -> bool expr | Or : bool expr * bool expr -> bool expr Evaluation function: let rec eval : type a. a expr -> a = function | Num n -> n | Add (a, b) -> (eval

Odd ghc error message, “My brain just exploded”?

拜拜、爱过 提交于 2019-11-26 23:06:59
问题 When I try to pattern-match a GADT in an proc syntax (with Netwire and Vinyl): sceneRoot = proc inputs -> do let (Identity camera :& Identity children) = inputs returnA -< (<*>) (map (rGet draw) children) . pure I get the (rather odd) compiler error, from ghc-7.6.3 My brain just exploded I can't handle pattern bindings for existential or GADT data constructors. Instead, use a case-expression, or do-notation, to unpack the constructor. In the pattern: Identity cam :& Identity childs I get a