[Haskell-beginners] Wildcards in expressions

Dean Herington heringtonlacey at mindspring.com
Wed Jan 26 05:43:27 CET 2011


At 9:34 PM -0500 1/25/11, Tom Murphy wrote:
>Hi everyone,
>      Any suggestions?
>
>
>Given that
>
>           someList :: [(a,b,String)]
>
>, the expression
>
>           (_, _, "Tom") `elem` someList
>
>seems so intuitive that, even though it doesn't work, I've been 
>searching for several hours for something similar.
>
>
>      Do any of you know a way I can pull this off? I know there are 
>plenty of ways to get the functionality, but something similarly 
>intuitive and succinct would be great.
>
>Thanks for the help,
>Tom

Wildcards (the underscores) can appear only in patterns.  You could 
use a list comprehension, something like:

     (not . null) [ () | (_, _, "Tom") <- someList ]

Dean



More information about the Beginners mailing list