Last active
August 29, 2015 14:12
-
-
Save plaidfinch/f9e0de5114abf24c5c41 to your computer and use it in GitHub Desktop.
List of Dicts?
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 GADTs #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
import Data.Constraint | |
import Data.Proxy | |
data Product (f :: k -> *) (xs :: [k]) where | |
(:*:) :: f x -> Product f xs -> Product f (x ': xs) | |
Nil :: Product f '[] | |
type family All (c :: k -> Constraint) (xs :: [k]) :: Constraint where | |
All c '[] = () | |
All c (x ': xs) = (c x, All c xs) | |
newtype Compose f g a = Compose { getCompose :: f (g a) } | |
dicts :: All c xs => Proxy c -> Product Proxy xs -> Product (Compose Dict c) xs | |
dicts = _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reddit thread about this code is at: http://www.reddit.com/r/haskell/comments/2qwqf2/generate_list_of_dicts_from_type_level_list/