You can do that. If you're getting an error, it's from a mistake on some other line. That said, you shouldn't write it that way. length requires a traversal of the entire list, so if the list is 1000 elements long it will take 1001 steps to compute that result when two steps would do. `length (take 2 a) == 1` would be a constant time way to get the result you want, although likely not the most elegant way to solve this exercise.

Perhaps this is the sort of question better suited for the haskell-beginners mailing list: https://www.haskell.org/mailman/listinfo/beginners

On Sun, Nov 9, 2014 at 10:33 AM, Roelof Wobben <r.wobben@home.nl> wrote:
Hello,

I try to make a guarded solution to find the last item in a list.

I thought I could do something like this

| length a == 1 = a

But then I see a lot of error messages.

Is there another way I can check the length of a list with guards ?

Roelof

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe