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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:03:52+00:00 2026-05-31T11:03:52+00:00

If I call the following Haskell code find_first_occurrence :: (Eq a) => a ->

  • 0

If I call the following Haskell code

find_first_occurrence :: (Eq a) => a -> [a] -> Int
find_first_occurrence elem list = (snd . head) [x | x <- zip list [0..], fst x == elem]

with the arguments

'X' "abcdXkjdkljklfjdlfksjdljjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"

how much of the zipped list [('a',0), ('b',1), ] is going to be built?

UPDATE:

I tried to run

find_first_occurrence 10 [1..]

and returns 9 almost instantly, so I guess it does use lazy evaluation at least for simple cases? The answer is also computed “instantly” when I run

let f n = 100 - n
find_first_occurrence 10 (map f [1..])
  • 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-31T11:03:53+00:00Added an answer on May 31, 2026 at 11:03 am

    All of it.

    Since StackOverflow won’t let me post such a short answer: you can’t get away with doing less work than looking through the whole list if the thing you’re looking for isn’t there.

    Edit: The question now asks something much more interesting. The short answer is that we will build the list:

    ('a',0):('b',1):('c',2):('d',3):('X',4):<thunk>
    

    (Actually, this answer is just the slightest bit subtle. Your type signature uses the monomorphic return type Int, which is strict in basically all operations, so all the numbers in the tuples above will be fully evaluated. There are certainly implementations of Num for which you would get something with more thunks, though.)

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

Sidebar

Related Questions

In my Fortran code I made the following call to the dnrm2 routine: d
I want to call the following function from my managed code: short LS_LoadConfig(LS_ID SensorID,LPVARIANT
Im trying to call the following code: Ext.namespace(menu); menu.menuItems = function(){ var menuItems= [{
here is how i call the following function: List<decimal> numbers = new List<decimal>(); numbers.Add(210m);
I have just noticed that when i call the following code from a console
How can I call the following method from another method on same code behind
I am Intercepting outgoing call following is my code of outgoing call interception public
I call the following function with a mouseover event but it's not working. My
I call the following function with Call GameTimer(FormatDate(objLiveCommentary(DateFirstStarted), WithTime), FormatDate(objLiveCommentary(DateSecondStarted), WithTime), Soccer) And it
I make the following call to the DB. @patientRegistration = PatientRegistration.find(:all, :conditions=>[name = '#{patientName}'])

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.