digit
digit

Reputation: 275

how can i make the target of a conditional be any of many? search for any of a list of strings rather than just one string? In Haskell

In:

eval x | "?" `isSuffixOf` x = privmsg (if "what" `isPrefixOf` x then "that would be an ecumenical matter" else "yes")

How can I have "what" be any of "what|who|how|why|where|when"?

I know it's not with | like that^, nor is it

eval x | "?" `isSuffixOf` x = privmsg (if "what" "who" "how" "why" "where" "when" `isInfixOf` x then "that would be an ecumenical matter" else "yes")

but I'm unsure of the logic of whatever syntactical fail I'm hitting upon, so everything else I'm trying are similar stabs in the dark, including searches.

(And how can I phrase this question better than "How can I make the target of a conditional be any of many?"? (As in, what are the terms I mean, that will better help me understand the situation and better form the search terms?)

Upvotes: 0

Views: 47

Answers (1)

rampion
rampion

Reputation: 89093

You want any:

interrogatives = ["what", "who", "how", "why", "where", "when"]

eval x | "?" `isSuffixOf` x = privmsg (
  if any (`isInfixOf` x) interrogatives 
     then "that would be an ecumenical matter" 
     else "yes"
  )

Upvotes: 5

Related Questions