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

  • Home
  • SEARCH
  • 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 8223319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:39:12+00:00 2026-06-07T14:39:12+00:00

My task is to re-implement this function divn :: Integer -> [Integer] -> [Integer]

  • 0

My task is to re-implement this function

divn :: Integer -> [Integer] -> [Integer]
divn _ [] = []
divn n (x:xs) | mod x n == 0 = x : divn n xs
              | otherwise = divn n xs

using ‘foldr’.
What I did:

divn' _ [] = []
divn' n (x:xs) = foldr (\x -> if (mod x n == 0) (x:) ([]++)) [] xs

I thought this would work. Actually it doesn’t even compile, but says: “Parse error on input “)”.

As I didn’t find any errors, I decided to re-write if as if’ an now its working…

if' True x _ = x
if' False _ x = x

divn' _ [] = []
divn' n (x:xs) = foldr (\x -> if' (mod x n == 0) (x:) ([]++)) [] xs

Does anyone know where’s the error?

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-07T14:39:15+00:00Added an answer on June 7, 2026 at 2:39 pm

    if needs a then and an else in Haskell,

    (\x -> if (mod x n == 0) (x:) ([]++))
    

    should be

    (\x -> if (mod x n == 0) then (x:) else id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this page offered sample code that would be ideal for a task I'm working
This is a beginner level task. I am trying to implement a calendar widget
Assume that you're working a x86 32-bits system. Your task is to implement the
I am trying to implement a gradle task to dynamically create a buildsignature.properties file
I am trying to implement a rake task that will run once a month
I am trying to implement some kind of new Linux task scheduler so I
I need to implement something. Something that could do some certain task in my
I need to implement task which is quite common feature for RichTextEditors - take
I am trying to implement Factorial function via divide and conquer strategy. I used
Background: I recently completed a tic-tac-toe game in AS3, using some simple function-based code

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.