[Haskell-cafe] ANNOUNCE: tagged-list v1.0

Gregory Crosswhite gcross at phys.washington.edu
Wed Oct 13 22:17:41 EDT 2010


  Hey everyone,

I am pleased to announce the release of tagged-list version 1.0, a 
package which provides fixed-length lists that are tagged with a phantom 
type-level natural number corresponding to the length. The advantage of 
such lists is that you can make static guarantees about them, so that 
for example the function

addLists :: TaggedList n Int -> TaggedList n Int -> TaggedList n Int
...

which adds two lists is guaranteed to get two lists of the same length 
and to produce a list with the same length as the inputs. Some basic 
operations on these lists have been provided, including instances for 
Applicable, Traversable, etc. One of the more interesting of these 
operations is the "join" function",

join :: TaggedList m α → TaggedList n α → (TaggedList (Plus m n) 
α,TaggedList (Plus m n) β → (TaggedList m β,TaggedList n β))

This function takes two lists and appends them, and returns not only the 
appended list but also a function that takes a list of the same length 
and splits it into two lists with the same lengths as the inputs; one 
way of interpreting the second parameter is that it provides a "proof" 
that a TaggedList of type TaggedList (Plus m n) β can be broken into 
lists of type TaggedList m β and TaggedList n β. This function is 
provided because I couldn't figure out how to make a general "split" 
function pass the type-checker, and fortunately I found that in practice 
I didn't need a general such function because I was usually taking a 
list that was the result of some operation applied to two lists I had 
earlier appended and breaking the result list into sublists the lengths 
of the original two lists.

I also provided functions to convert tagged lists to and from tuples, 
which can be useful at the times when the type-checker gets confused by 
your "a :. b :. ... :. E" expression and gives you obscure error messages.

Anyway, I hope that the community finds this package useful, and welcome 
any feedback that you all have to offer.

Cheers,
Greg



More information about the Haskell-Cafe mailing list