Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created February 10, 2015 18:17
Show Gist options
  • Save gclaramunt/d6f8da3d969dfc526c60 to your computer and use it in GitHub Desktop.
Save gclaramunt/d6f8da3d969dfc526c60 to your computer and use it in GitHub Desktop.
Heterogeneous list in Haskell
{-# LANGUAGE GADTs #-}
module HLists where
data Hlist where
HNil :: Hlist
HCons :: a-> Hlist -> Hlist
HConsShw :: Show a => a-> Hlist -> Hlist -- show here is horrible
instance Show Hlist
where show HNil = ""
show (HCons a l) = "?" ++ ","++ show l
show (HConsShw a l) = show a ++","++ show l
main = do
putStrLn $ show $ HConsShw "123" (HConsShw 1 ( HConsShw 'a' HNil))
--"123",1,'a',
putStrLn $ show $ HConsShw "123" (HCons 1 ( HConsShw 'a' HNil))
--"123",?,'a',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment