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

  • SEARCH
  • Home
  • 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 6710977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:05:06+00:00 2026-05-26T08:05:06+00:00

I have a data called Sample, defined as data Sample = Test1 (String,[[String]]) |

  • 0

I have a data called “Sample”, defined as

data Sample = Test1 (String,[[String]])
             | Test2 (String,[[String]])

Then I create a list[Sample] called “Samples”, say

[Test1 ("Sample1",[["works","running"]]), Test2 ("Sample2", []),
 Test1 ("Sample3", [["aborts"]] ]

Now, I need to check whether “aborts” is present under “Sample3”. I have a basic
idea of how to do it but I am not sure how to implement it in Haskell.

My idea is

check:: String -> [String] -> [Sample] -> Bool
check samplename result samples =

I can call it by:

check "Sample3" ["aborts"] Samples

But how do I implement this function.


I have solved like this but I am looking for a better version.

My version is:

check:: String -> [String] -> [Sample] -> Bool
check samplename result samples = 
  if( "True" `elem` final ) 
  then True 
  else False
    where 
      final = [x | sample <- samples, 
                   x <- [ case sample of
                               Test1 (name,res) = 
                                 if name == samplename && (result `elem` res) 
                                 then "True" 
                                 else "False"
                               Test2 (name, res) = "False"]]
  • 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-26T08:05:07+00:00Added an answer on May 26, 2026 at 8:05 am

    Here is my version of the solution. But I dont think your data represent any real problem , you can easily use Map if you want to store something like [Sample] which is basically a list of key value pairs. Well the idea behind my solution is also inspired from Map . I have written a lookup' function similar to lookup which given a key returns the value . writing the rest function is trivial then. Similar to your approach but less messy .

    data Sample = Test1 (String,[[String]])
                 | Test2 (String,[[String]])
            deriving Show
    samples = [ Test1 ("Sample1",[["works","running"]]), Test2 ("Sample2", []), Test1    ("Sample3", [["aborts"]]) ]
    
    fromSample :: Sample -> (String,[[String]])
    fromSample (Test1 x) = x
    fromSample (Test2 x) = x
    
    lookup' :: String -> [Sample] -> Maybe [[String]]
    lookup' str [] = Nothing
    lookup' str (x:xs) | fst pair == str = Just $ snd pair
                   | otherwise = lookup' str xs
                where pair = fromSample x
    
    check :: String -> [String] -> [Sample] -> Bool
    check sample str xs = case lookup' sample xs of
                            Nothing -> False 
                            Just list -> str `elem` list 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class that has a member called data which is
I have a User-Defined Table Type called tvpInsertedColumns : CREATE TYPE [Audit].[tvpInsertedColumns] AS TABLE(
Let's say we have a simple table defined as: <p:dataTable value=#{testBean.dummyStringData} var=data> <p:column> <p:commandLink
I have a Data Class called MyTable, and the source property is TABLE (table
I have a data.frame called series_to_plot.df which I created by combining a number of
I have a project called Data which is a data layer. In this project,
I have a data object -- a custom class called Notification -- that exposes
I have the following data: A post called Hello has categories greet Another post
I have tons of data in directory called reports. While doing git merge with
I have a data tier select method that returns a datatable. It's called from

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.