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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:01:00+00:00 2026-05-21T09:01:00+00:00

The code below starting with digits returns a List of integers. The code starting

  • 0

The code below starting with digits returns a List of integers. The code starting with altSumOfDigits should return just the same list, but instead Prelude is complaining about a type error, which i don’t understand at this point.

Couldn't match expected type `a' against inferred type `Integer'


digits' :: Integer -> [Integer]
digits' 0 = []
digits' x = (x `mod` 10) : digits' (x `div` 10)

digits :: Integer -> [Integer]
digits 0 = [0]
digits x = reverse $ digits' x

altSumOfDigits :: Integer -> [a]
altSumOfDigits num = [ x | x <- (digits num)]

(I know that altSumOfDigits num = [ x | x <- (digits num)] is rather useless in this form. I’m going to extend its functionality with an if-expression and operations on the single Integers later.)
Any explanations why this doesn’t work?

  • 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-21T09:01:00+00:00Added an answer on May 21, 2026 at 9:01 am

    Change (or remove) the type of altSumOfDigits to return a [Integer].


    Including the error in the question is good form, and here it is:

    Couldn't match type `a' with `Integer'
    

    The type of altSumOfDigits takes a list of Integer, but returns a list of any type a, according to the type you have declared. So it is polymorphic in its return type.

    However, you call digits from within altSumOfDigits, which must return a list of Integer only. There is thus no way your altSumOfDigits could return anything other than a list of [Integer].

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

Sidebar

Related Questions

In the code below, I am able to call BackgroundJob.starting(job_script) just fine. However, I
The code below works. But if I comment out the line Dim objRequest As
The code below is checking performance of three different ways to do same solution.
I tried to use the code below in Wix. But when installing, the installer
I have a bunch of movieclips that are animated using TweenLite, (code below), but
I'm just starting WPF so am just learning but I've ran into a problem
My Apache install is having issues starting with PHP? The code below kills the
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
The code below shows a sample that I've used recently to explain the different

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.