[Haskell-cafe] beginner's problem about lists
fis at wiwi.hu-berlin.de
Tue Oct 10 11:02:43 EDT 2006
On Tue, Oct 10, 2006 at 08:58:05AM -0400, Lennart Augustsson wrote:
> >a function that takes two lists and decides whether one of them is
> >finite or not , without being given further information on the lists,
> >does not exist.
> A function that takes two lists and decides if one is finite does
> indeed exist. But if both are infinite you'll get partial
> information out.
> The example
> shorter [1..5] (shorter [2..] [3..])
> is a little tricky, but certainly doable.
right, my implementation wouldn't cover this case.
i was meaning termination, though: if a function accepts two possibly
infinte lists, it cannot unconditionally return with the shorter one.
i think the best you can do is Hennings solution (and mine, but i was
too slow :) that hits bottom once you touch any element in (shorter
[2..] [3..]), instead of merely the lengths of its prefices.
More information about the Haskell-Cafe