Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Created October 18, 2022 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LSLeary/7e551b7ca6f26fa9d8ed26f718f9f78d to your computer and use it in GitHub Desktop.
Save LSLeary/7e551b7ca6f26fa9d8ed26f718f9f78d to your computer and use it in GitHub Desktop.
Zippy Heterogeneous Lists
{-# LANGUAGE DataKinds, GADTs #-}
module Zip where
import Data.Kind (Type)
data Zippy :: (k1 -> k2 -> Type) -> [k1] -> [k2] -> Type where
Nil :: Zippy f '[] '[]
(:~) :: f x y -> Zippy f xs ys -> Zippy f (x:xs) (y:ys)
newtype Fst a b = Fst{ getFst :: a }
newtype Snd a b = Snd{ getSnd :: b }
zipApply :: Zippy (->) xs ys -> Zippy Fst xs ys -> Zippy Snd xs ys
zipApply Nil Nil = Nil
zipApply (f :~ fs) (Fst x :~ xs) = Snd (f x) :~ zipApply fs xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment