Created
February 20, 2024 22:24
-
-
Save ramirez7/4de8396128c74aa5ea8eb1db42228084 to your computer and use it in GitHub Desktop.
HList via GADTs
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 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