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 7981223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:18:17+00:00 2026-06-04T10:18:17+00:00

Hi I’m currently trying to use the elem function in prelude. data MyType =

  • 0

Hi I’m currently trying to use the elem function in prelude.

data MyType = A Int
            | B Int Int
            | C Int
            | D Int Int
     deriving (Show,Eq)

list = [ A _, B _ _ ]    

or

list = [ A Int, B Int Int ]

bool = (A 12) elem list  -- use like this to get a Boolean value.

The problem is the list, it will (both) have compile error. Can someone tell me the right way to define list?

Oops about the data and deriving (Show,Eq) in my main code I did do all that. The reason for this question is that I have a big list of MyType and I want to cherry pick one or two of the types out of the big list modify it then put it back, how do I do that?
Exp.
bigList=[ A 3, C 6, A 5, B 5 8, D 5 6 ]
I would like to pick out only the data type ( A Int ) and (B Int Int) , maybe change all value for the two data type into 0, after modification put back so I end up with a new list.
newBigList=[ A 0, C 6, A 0, B 0 0, D 5 6 ]

Thanks

  • 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-06-04T10:18:18+00:00Added an answer on June 4, 2026 at 10:18 am

    First of all, it is data and not Data.
    Second, you are mixing type variables (Int) with values in defining list, while _ can only be used in pattern matching. You should write this instead to build a list of type [MyType]:

    list = [A 12, B 1 5]
    

    Third, your declaration for bool uses elem :: Eq a => a -> [a] -> Bool as an infix operator, while it is a function like any other. Write either

    bool = elem (A 12) list
    

    or

    bool = (A 12) `elem` list
    

    As you see from the type signature of elem, you need to derive the Eq typeclass. It could be useful to be able to print your MyType values also, so you may consider adding deriving (Eq,Show) at the end of your type declaration.

    It seems like you’re mistaking Haskell for Prolog. Haskell do not work by unification like Prolog. You should start reading a good tutorial or book from the basics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.