[Haskell-beginners] first number is a list

David Virebayre dav.vire+haskell at gmail.com
Mon Jun 27 13:48:55 CEST 2011

2011/6/27 Roelof Wobben <rwobben at hotmail.com>:
> Hello,
> I have to find the first number is a list.
> So first I tried :
> let mylast = last [1,2,3,4]
> mylast

I'm confused :
You say have to find the first number of a list but this gives you the last.

> [x | x <- [1,2,3,4] , last ]

> But then I see these error :
> Could not match expected type "Bool" with actual type [a0] -> a0

It's quite clear: The compiler expects a function that'll return a
Bool value, but you gave it one that takes a list and returns an
element from the list.

Additional terms in the list comprehention are meant to be filters on
elements of the list, not functions that work on the list.


More information about the Beginners mailing list