[Haskell-beginners] Type polymorphism with size

Michael Snoyman michael at snoyman.com
Wed Nov 19 00:37:16 EST 2008


On Tue, Nov 18, 2008 at 5:16 PM, Brent Yorgey <byorgey at seas.upenn.edu>wrote:

> > class RepTuple a b | a -> b where
> >     toList :: a -> [b]
> >     tMap :: (b -> b) -> a -> a
> >
> > instance RepTuple (a, a) a where
> >     toList (a, b) = [a, b]
> >     tMap f (a, b) = (f a, f b)
> >
> > And so on and so forth for every kind of tuple. Of course, this runs into
> > the issue of the single case, for which I used the OneTuple library
> > (actually, I wrote my own right now, but I intend to just use the
> OneTuple
> > library).
> >
>
> This is reasonable too.  It's just a tradeoff of hackishness vs. code
> length/tediousness. I.e. in the solution with type-level naturals, you
> don't need a separate instance like this for every number you're going
> to use.  And no one really likes writing things like
> tMap f (a,b,c,d,e,g,h,i,j) = ...  =)
>
> -Brent
>

I agree that it's not something people want to code; I was just thinking
that a RepTuple kind of library might be useful for other purposes (ensuring
lists of certain length essentially).

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081118/f8e54b53/attachment.htm


More information about the Beginners mailing list