
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
finiteness.
/J
On 13 October 2010 16:41, Stephen Tetley
Hi Jonas
Nice, but how about a list destructor?
;-) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe