[Haskell-cafe] Finite but not fixed length...

Jonas Almström Duregård jonas.duregard at chalmers.se
Wed Oct 13 11:04:17 EDT 2010

> Nice, but how about a list destructor

I'm not sure what you mean by destructor, if you mean an eliminator for
case analysis then you can make a function

finite :: b -> (a -> Finite s1 a -> b) -> Finite s2 a -> b
finite b _ (Finite [])     = b
finite _ f (Finite (x:xs)) = f x xs

If you men functions that possibly remove elements from lists, then you can
add definitions like these to the module:

filter = onList . Prelude.filter
tail = onList Prelude.tail

onList :: ([a] -> [b]) -> Finite s a -> Finite s b
onList f = Finite . f . infinite

Don't export onList though! filter and map should be enough to define any
list function you want outside the module.

Note that the size-type doesn't correspond exactly to the size of the list,
but that's not really a problem as long as you only want to guarantee


On 13 October 2010 16:41, Stephen Tetley <stephen.tetley at gmail.com> wrote:

> Hi Jonas
> Nice, but how about a list destructor?
>  ;-)
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101013/1e8f0ebc/attachment.html

More information about the Haskell-Cafe mailing list