Skip to content

Instantly share code, notes, and snippets.

@jkachmar
Created April 25, 2017 22:08
Show Gist options
  • Select an option

  • Save jkachmar/8f5c8c44aa555dfae6f4df04543c814e to your computer and use it in GitHub Desktop.

Select an option

Save jkachmar/8f5c8c44aa555dfae6f4df04543c814e to your computer and use it in GitHub Desktop.
Showable HList
{-# 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