Guest User

Untitled

a guest
Dec 17th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. data Vect :: Nat -> * -> * where
  2. Cons :: KnownNat n => a -> Vect (n - 1) a -> Vect n a
  3. Nil :: (KnownNat n, 0 <= n) => Vect n a
  4.  
  5. k :: Vect 1 Int
  6. k = Cons 1 Nil
  7.  
  8. u :: Vect 0 Int
  9. u = Nil
  10.  
  11. j = vhead k
  12.  
  13. p = vtail k
  14.  
  15. vhead :: KnownNat n => Vect (n + 1) a -> a
  16. vhead (Cons x _) = x
  17.  
  18. vtail :: (KnownNat n, n ~ (n + 1 - 1)) => Vect (n + 1) a -> Vect n a
  19. vtail Nil = Nil
  20. vtail (Cons _ xs) = xs
  21.  
  22. vzip :: Vect n a -> Vect n b -> Vect n (a, b)
  23. vzip Nil Nil = Nil
  24. vzip (Cons x xs) (Cons y ys) = Cons (x, y) $ vzip xs ys
  25.  
  26. vindex :: (KnownNat n, KnownNat i, i <= n - 1) => Proxy i -> Vect n a -> a
  27. vindex (pi :: Proxy i) (Cons x xs) =
  28. case natVal pi of
  29. 0 -> x
  30. _ -> vindex (Proxy :: Proxy (i - 1)) xs
Add Comment
Please, Sign In to add comment