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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:54:44+00:00 2026-05-17T02:54:44+00:00

My function looks like this: minus :: (Eq a) => [a] -> [a] ->

  • 0

My function looks like this:

minus :: (Eq a) => [a] -> [a] -> [a]
minus [] xs                      = []
minus (y:ys) xs | y `notElem` xs = y : (minus ys xs)
                | otherwise      = minus ys xs

It can be used like this:

[99,44,55,22,23423] `minus` [55,22]

with output: [99,44,23423]

I wrote this because I’m looking at Project Euler problem 7, and the Sieve of Eratosthenes seems like the right tool, and it was, but I kept reading down the Wikipedia page and got to the part about Euler’s sieve.

I tried to copy/paste the code and run it in GHCi, but my version of GHCi doesn’t have a module called Data.OrdList, and I couldn’t find a function called minus in Hoogle.

This is the code from Wikipedia:

 import Data.OrdList (minus)

 primes = euler [2..]
 euler (p : xs) = p : euler (xs `minus` map (*p) (p : xs))

If I substitute my minus function in there, I get an out of memory error, because my function isn’t lazy.

Is there a way to make a lazy minus function?

Does my minus function do the same as the minus function in the Wikipedia article?

  • 1 1 Answer
  • 2 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-17T02:54:45+00:00Added an answer on May 17, 2026 at 2:54 am

    As sepp2k pointed out, the implementation of minus must assume ordered lists. Here goes a possible implementation:

    minus :: Ord a => [a] -> [a] -> [a]
    minus [] _ = []
    minus xs [] = xs
    minus l1@(x:xs) l2@(y:ys)
        | x > y = minus l1 ys
        | x < y = x : minus xs l2
        | otherwise = minus xs l2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My javascript function looks like this - function updateSuccess(aEle) { //Here aEle doesn't have
I'm using openURL to send an email w/some links. The function looks like this:
A function header looks like this function doit($theparam){ //$theparam is untrimmed $theparam = trim($theparam);
In a template function that looks like this: template<typename T> constexpr T foo(T a,
i have a function that looks like this. function startChatSession($items) { foreach ($test as
I have a JavaScript function that looks like this: function recalculateWhatIfCurrentRate(aEle, aChangedLabel, recordID, yearEndCurrentRate)
Suppose I have a function which looks like this: template <class In, class In2>
I've built a jQuery selector for a function which looks like this: $('html').not('.table-main tr[selected]').mousedown(
I have a function which looks something like this, it returns a noncopyable class
I have a constexpr function that looks something like this: constexpr int foo(int bar)

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.