Skip to content

Instantly share code, notes, and snippets.

@kosmikus
Created April 18, 2017 20:10
Show Gist options
  • Save kosmikus/0bedbd1b3eb1c5037bc8bcb8d35a56ba to your computer and use it in GitHub Desktop.
Save kosmikus/0bedbd1b3eb1c5037bc8bcb8d35a56ba to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module MapDict where
import Generics.SOP
import Generics.SOP.Dict
type family Map (f :: k -> l) (xs :: [k]) :: [l] where
Map _f '[] = '[]
Map f (x ': xs) = f x ': Map f xs
mapDict :: forall f xs . Proxy f -> SList xs -> Dict SListI (Map f xs)
mapDict pf SNil = Dict
mapDict pf SCons = goCons (sList :: SList xs)
where
goCons :: forall y ys . SList (y ': ys) -> Dict SListI (Map f (y ': ys))
goCons SCons = withDict (mapDict pf (sList :: SList ys)) Dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment