Created
May 30, 2018 15:26
-
-
Save CarstenKoenig/57611331eb00ec405040ca9eda90abfb to your computer and use it in GitHub Desktop.
Vector map 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 GADTs #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeInType #-} | |
{-# LANGUAGE TypeOperators #-} | |
module VectMap where | |
import GHC.TypeLits | |
data Vect (n :: Nat) a where | |
Nil :: Vect 0 a | |
Cons :: a -> Vect n a -> Vect (1 + n) a | |
vMap :: (a -> b) -> Vect n a -> Vect n b | |
vMap _ Nil = Nil | |
vMap f (Cons a as) = f a `Cons` vMap f as |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment