Created
April 25, 2017 22:08
-
-
Save jkachmar/8f5c8c44aa555dfae6f4df04543c814e to your computer and use it in GitHub Desktop.
Showable HList
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 ConstraintKinds #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module ThisIsWeird where | |
| import ClassyPrelude | |
| import Data.Kind (Constraint) | |
| data HList xs where | |
| HNil :: HList '[] | |
| HCons :: a -> HList as -> HList (a ': as) | |
| type family ConstrainAllHList (c :: * -> Constraint) (ls :: [*]) :: Constraint | |
| type instance ConstrainAllHList c '[] = () | |
| type instance ConstrainAllHList c (x ': xs) = (c x, ConstrainAllHList c xs) | |
| showAllHList :: ConstrainAllHList Show xs => HList xs -> [String] | |
| showAllHList HNil = [] | |
| showAllHList (HCons x xs) = (show x) : (showAllHList xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment