Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:58:59+00:00 2026-05-30T02:58:59+00:00

findMatch :: [String] -> [String] findMatch xs = let keywords = [(data, set)] in

  • 0
findMatch :: [String] -> [String]
findMatch xs =
    let keywords = [("data", "set")]
    in [ if null x then "null" else fst y | x <- xs, y <- keywords, (snd y) == x]

Everything in this function works except for the then. If the (snd y) can’t be matched to x (the x is drawn from a list of words sent by the user), I’d like to return a string that says “null.”

in [ if (snd y) == x then fst y else "null" | x <- xs, y <- keywords]

Writing the list comprehension this way (thanks byorgey) works better, but then “null” is returned more times than I need it to be when more than 1 set of words are used in my keywords variable. I only need the string “null” to return once.

Maybe Haskell has a kind of break that I could add?

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:59:00+00:00Added an answer on May 30, 2026 at 2:59 am

    I think what you want is

    let keywords = [("data","set")]
    in [maybe "null" fst $ find ((== x) . snd) keywords | x <- xs]
    

    unless the keywords list can contain several pairs with the same second component and you want them all listed, then it would be

    in concat [case [key | (key,word) <- keywords, word == x] of { [] -> ["null"]; ms -> ms; } | x <- xs]
    

    In the first case, it would be nicer if the keywords pairs were swapped,

    let keywords = [("set", "data")]
    in [fromMaybe "null" $ lookup x keywords | x <- xs]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this question someone replies You never let the domain object implementations call services
I have the function below that copies a file in a directory and recreate
The file Mexico.Data.dll is at /bin/ and other pages references it without error, what's
I have a problem using the Java search function in Eclipse on a particular
This originally was a problem I ran into at work, but is now something
How to handle null when using Pattern.compile ? I'm using the following line to
The pertinent part of my .htaccess looks like this: Options -Indexes <FilesMatch include> Order
I have a few files like this- *.sss and *_passive.sss If I have a
I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have a readData() function that reads files a returns a few different objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.