[Haskell-beginners] Heterogeneous Lists

Mike Ledger eleventynine at gmail.com
Tue May 28 12:31:08 CEST 2013


With ConstraintKinds, ExistentialQuantification, StandaloneDeriving and
FlexibleInstances, this works:
>>> data Some f = forall a. f a => Some a
>>> deriving instance Show (Some Show)
>>> show ([Some [0..10], Some (), Some Nothing, Some "asdf"] :: [Some Show])
"[Some [0,1,2,3,4,5,6,7,8,9,10],Some (),Some Nothing,Some \"asdf\"]"


On Tue, May 28, 2013 at 6:04 PM, Magnus Therning <magnus at therning.org>wrote:

> On Tue, May 28, 2013 at 9:36 AM, harry <voldermort at hotmail.com> wrote:
> > Every OO language which supports generics allows a declaration such as
> > List<Show> alist, where Show is an interface. Any type implementing Show
> can
> > be put in alist, and any Show operation can be performed on the alist's
> > members. No casts, wrappers, or other special types and plumbing are
> needed.
> >
> > Why isn't it possible to do this directly in Haskell?
>
> Just to make sure... I guess you've already read
> http://www.haskell.org/haskellwiki/Heterogenous_collections right?
>
> /M
>
> --
> Magnus Therning                      OpenPGP: 0xAB4DFBA4
> email: magnus at therning.org   jabber: magnus at therning.org
> twitter: magthe               http://therning.org/magnus
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130528/3fa1a1cc/attachment.htm>


More information about the Beginners mailing list