Created
February 10, 2015 18:17
-
-
Save gclaramunt/d6f8da3d969dfc526c60 to your computer and use it in GitHub Desktop.
Heterogeneous list in Haskell
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 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