Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Created February 20, 2024 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramirez7/4de8396128c74aa5ea8eb1db42228084 to your computer and use it in GitHub Desktop.
Save ramirez7/4de8396128c74aa5ea8eb1db42228084 to your computer and use it in GitHub Desktop.
HList via GADTs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
module HList.GADT where
import Data.Kind
data HList (ts :: [Type]) where
HNil :: HList '[]
HCons :: forall t ts. t -> HList ts -> HList (t ': ts)
instance (Show t, Show (HList ts)) => Show (HList (t ': ts)) where
show (HCons t ts) = "HCons " ++ show t ++ " (" ++ show ts ++ ")"
instance Show (HList '[]) where
show HNil = "HNil"
example :: HList [Int, Bool, String]
example = HCons 2 $ HCons True $ HCons "hi" $ HNil
{-
λ example
HCons 2 (HCons True (HCons "hi" (HNil)))
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment