Skip to content

Instantly share code, notes, and snippets.

@greatBigDot
Last active February 22, 2020 03:48
Show Gist options
  • Select an option

  • Save greatBigDot/68e7a32e4802a7359450077bf03cbe88 to your computer and use it in GitHub Desktop.

Select an option

Save greatBigDot/68e7a32e4802a7359450077bf03cbe88 to your computer and use it in GitHub Desktop.
Natural numbers and vectors and such
{-# LANGUAGE UnicodeSyntax, NoStarIsType, LambdaCase #-}
{-# LANGUAGE GADTs, DataKinds, PolyKinds, PatternSynonyms, ViewPatterns, TypeApplications #-}
module Utils where
import Data.Kind
-- The usual definitions of Nat and Vec:
data Nat = Z | S Nat
data Vec :: Nat -> Type -> Type where
VNil :: Vec 'Z a
(:>) :: a -> Vec n a -> Vec ('S n) a
instance Functor (Vec n) where
fmap _ VNil = VNil
fmap f (x:>xs) = f x :> fmap f xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment