[Haskell-beginners] List of a Data Type
tjakway at nyu.edu
Tue Nov 3 22:24:05 UTC 2015
I've made a new datatype
data Visibility a = Hidden a | Shown a
I want to create a type that's a list of hidden and visible integers.
So something like this:
type possiblyVisibleInts = [Visibility Int]
The idea is that some of the ints will be hidden and some will be shown.
But it doesn't work. Why not?
This seemed even odder to me after poking around in ghci:
:t [Just 5, Nothing]
[Just 5, Nothing] :: Num a => [Maybe a]
So clearly it's possible to have a list of a type that has 2
constructors--you're not restricted to having a list that only contains
Just, for example.
ghci is also OK with e.g.
:t [Hidden 5, Shown 6]
[Hidden 5, Shown 6] :: Num a => [Visibility a]
More information about the Beginners