Created
April 18, 2017 20:10
-
-
Save kosmikus/0bedbd1b3eb1c5037bc8bcb8d35a56ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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