[Haskell-beginners] List of a Data Type
ahammel87 at gmail.com
Tue Nov 3 22:34:19 UTC 2015
Works for me:
Prelude> data Vis a = Hidden a | Shown a
Prelude> :t [Hidden "foo", Shown "bar"]
[Hidden "foo", Shown "bar"] :: [Vis [Char]]
Prelude> type VisListInt = [Vis Int]
Prelude> let foo = (id :: VisListInt -> VisListInt)
Prelude> :t foo
foo :: VisListInt -> VisListInt
Prelude> :t foo [Hidden 2]
foo [Hidden 2] :: VisListInt
What error message are you seeing?
On Tue, 3 Nov 2015 at 14:24 Thomas Jakway <tjakway at nyu.edu> wrote:
> 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]
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners