[Haskell-cafe] beginner's problem about lists
Colin DeVilbiss
cdevilbiss at gmail.com
Tue Oct 10 09:24:26 EDT 2006
On 10/10/06, falseep at gmail.com <falseep at gmail.com> wrote:
> I'm trying to implement a function that returns the shorter one of two given
> lists,
> something like
> shorter :: [a] -> [a] -> [a]
> However, it becomes difficult when dealing with infinite lists, for example,
> shorter [1..5] (shorter [2..] [3..])
> Could this evaluate to [1..5]? I haven't found a proper implementation.
If you can figure out a solution that works for both "shorter [1..5]
[2..]" and "shorter [2..] [1..5]", the essence of that solution will
work to define a "shortest [[1..5],[2..],[3..]]" (leaving "shorter a b
= shortest [a, b]").
As shown elsewhere in the thread, there is at least one solution with
slightly different type signatures that works much like you want;
something like:
unFoo (shorter' (foo a) (shorter' (foo b) (foo c)))
Colin
More information about the Haskell-Cafe
mailing list