Skip to content

Instantly share code, notes, and snippets.

@CarstenKoenig
Created May 30, 2018 15:26
Show Gist options
  • Save CarstenKoenig/57611331eb00ec405040ca9eda90abfb to your computer and use it in GitHub Desktop.
Save CarstenKoenig/57611331eb00ec405040ca9eda90abfb to your computer and use it in GitHub Desktop.
Vector map in Haskell
{-# 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