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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:45:26+00:00 2026-05-21T16:45:26+00:00

Is there any way of doing something like this in haskell ? data Fruits

  • 0

Is there any way of doing something like this in haskell ?

data Fruits = Apple Int | Orange Int deriving (Eq, Show)

basket = [Apple 2, Orange 4]

from_basket t (x:basket) =
    case x of
        (t i) -> i
        _ -> from_basket t basket

Now i want to get the ‘apple’ from the list of fruits ( basket )

from_basket Apple basket

Without an explicit pattern match

case x of
    Apple i -> ...
    Orange i -> ...
    _ ->
  • 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-21T16:45:27+00:00Added an answer on May 21, 2026 at 4:45 pm

    One way would be to define your own helper function isApple and then do filtering:

    isApple (Apple _) = True
    isApple _         = False
    
    getApples = filter isApple
    

    Pattern matching is the tool of your choice, I don’t know whether you can simplify this any further. But apart from some dirty template Haskell, I don’t see any other way.

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

Sidebar

Related Questions

Any way to emulate something like this? Isn't there an API for doing something
Anybody have any idea how I might go about doing something like this. I've
Is there any simple way to do something like jquery i.e. $('#image-gallery li:nth-child(3)').addClass('third-image-child') but
Is there any way to specify a width when doing :vsplit? Also, is there
Is there any way to achieve compiling Node.js scripts as native code, like Hip-Hop
Hi all I am doing something like this - void update(ClasstoUpdate obj)//obj is already
I'm currently doing something like this in SQLA: class Base(object): query = DBSession.query_property() @classmethod
Is there any simple way make count queries with Activate? What I'm doing today
In a Django view I'm doing something like this.. lists = Stuff.objects.exclude(model2=None) for alist
Right now I'm doing something like this: NSString *pullProcesses = @ps axco pid,pcpu,user,command; system([pullProcesses

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.