Sometime ago I needed something that Haskell don’t have by default: heterogeneous lists…
After think about that I decide to make my own “module” so I did this:
data Hetero where H :: forall a . Show a => a -> Hetero
instance Show Hetero where show (H s) = show s
In fact is just a data type and an instance to show the data. Nothing more, nothing less…
Here some examples of heterogeneous lists:
list , list2 :: [Hetero] list = [H ['a'..'z'], H 10, H '0', H 3.1, H [1..10]] list2 = [H [H [H '0', H [1..10]], H '0'], H 1]
By the way, the data type is write using Generalised Algebraic Data-Types (GADT). GADT is, in fact a very recent thing in Haskell, I will talk about that latter.
Some time ago, after doing this, I was searching GADT and find this after I find another one talking about
exists in Haskell, in that one, on the first example you can learn more about Heterogeneous Lists in Haskell and Haskell…
NOTE: Today I preferred blue.