[Haskell-beginners] List of a Data Type

Alex Hammel 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?

Cheers,
Alex

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]
> gives
> [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
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151103/135b3c25/attachment.html>


More information about the Beginners mailing list