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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:33:58+00:00 2026-05-26T03:33:58+00:00

What are the functions some and many in the Alternative type class useful for?

  • 0

What are the functions some and many in the Alternative type class useful for? Docs provide a recursive definition which I was unable to comprehend.

  • 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-26T03:33:58+00:00Added an answer on May 26, 2026 at 3:33 am

    some and many can be defined as:

    some f = (:) <$> f <*> many f
    many f = some f <|> pure []
    

    Perhaps it helps to see how some would be written with monadic do syntax:

    some f = do
      x <- f
      xs <- many f
      return (x:xs)
    

    So some f runs f once, then "many" times, and conses the results. many f runs f "some" times, or "alternatively" just returns the empty list. The idea is that they both run f as often as possible until it "fails", collecting the results in a list. The difference is that some f immediately fails if f fails, while many f will still succeed and "return" the empty list in such a case. But what all this exactly means depends on how <|> is defined.

    Is it only useful for parsing? Let’s see what it does for the instances in base: Maybe, [] and STM.

    First Maybe. Nothing means failure, so some Nothing fails as well and evaluates to Nothing while many Nothing succeeds and evaluates to Just []. Both some (Just ()) and many (Just ()) never return, because Just () never fails! In a sense they evaluate to Just (repeat ()).

    For lists, [] means failure, so some [] evaluates to [] (no answers) while many [] evaluates to [[]] (there’s one answer and it is the empty list). Again some [()] and many [()] don’t return. Expanding the instances, some [()] means fmap (():) (many [()]) and many [()] means some [()] ++ [[]], so you could say that many [()] is the same as tails (repeat ()).

    For STM, failure means that the transaction has to be retried. So some retry will retry itself, while many retry will simply return the empty list. some f and many f will run f repeatedly until it retries. I’m not sure if this is useful thing, but I’m guessing it isn’t.

    So, for Maybe, [] and STM many and some don’t seem to be that useful. It is only useful if the applicative has some kind of state that makes failure increasingly likely when running the same thing over and over. For parsers this is the input which is shrinking with every successful match.

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

Sidebar

Related Questions

I'm currently maintaining some flex code and noticed very many functions which are declared
Function type A -> B in some sense is not very good. Though functions
I've just came around dbjlets which was released in 2008. It adds many useful
While searching for some functions in C++ standard library documentation I read that push
I'm trying to encapsulate some functions from the C socket library into my own
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have some concerns related to the fact of testing some functions containing the
I want to copy some functions from OpenCV library to my embedded application. Rewriting
Our framework requires wrapping certain functions in some ugly boilerplate code: def prefix_myname_suffix(obj): def
I need to log some data when some functions are hit, both at the

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.