Created
April 20, 2015 20:02
-
-
Save tel/6e107c1a77992ed796db to your computer and use it in GitHub Desktop.
A rather non-traditional, non-Hask functor in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds | |
, TypeFamilies | |
, TypeOperators | |
, GADTs | |
, KindSignatures #-} | |
data Nat = Z | S Nat | |
type family Plus n m :: Nat where | |
Plus Z m = m | |
Plus (S n) m = S (Plus n m) | |
data Vector :: * -> Nat -> * where | |
Nil :: Vector a Z | |
Cons :: a -> Vector a n -> Vector a (S n) | |
append :: Vector a n -> Vector a m -> Vector a (Plus n m) | |
append l r = case l of | |
Nil -> r | |
Cons a as -> Cons a (append as r) | |
data n ~> m where | |
NilA :: n ~> Z | |
ConsA :: n ~> m -> n ~> Plus n m | |
-- Witness to the fact that `Vector a` is an object map from Nat to a subcategory | |
-- of Hask, Hask[Vector]. | |
nmap :: (n ~> m) -> (Vector a n -> Vector a m) | |
nmap x v = case x of | |
NilA -> Nil | |
ConsA q -> append v (nmap q v) |
Author
tel
commented
Apr 20, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment