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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:23:47+00:00 2026-06-12T03:23:47+00:00

I have the following code: betaRest :: Int -> [Int] -> Int betaRest n

  • 0

I have the following code:

betaRest :: Int -> [Int] -> Int
betaRest n prevDigits | n == 0    = (length prevDigits)
                      | otherwise = (sum (map (betaRest (n - 1)) [0..9]))

betaFirst :: Int -> Int
betaFirst n | n == 0    = 0
            | otherwise = (betaRest (n - 1) [1..9])

It gives me the following errors, and I don’t know why.

1) No instance for (Enum [Int]) arising from the arithmetic sequence ‘0 .. 9’

2) No instance for (Num [Int]) arising from the literal ‘0’

Does Haskell think that things made with the “..” operator are enumerations? But why isn’t there an error for the line that’s 4 lines below (with “[1..9]”) it then?


Edit: What I want the code to do is like this (procedurally):

int betaRest(int n, int[] prevDigits) {
  if (n == 0) return prevDigits.length;
  else {
    sum = 0;
    foreach prevDigit in prevDigits {
      sum += betaRest(n - 1, [0..9]);
    }
    return sum;
  }
}

int betaFirst(int n) {
  if (n == 0) return 0;
  else return betaRest(n - 1, [1..9]);
}

Thus, betaFirst(1) == 9, and betaFirst(2) == 90. Yes, somebody may want to suggest a formula for generating this, but I’m going to add a filter of some sort to [0..9], thus reducing the range.

  • 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-12T03:23:49+00:00Added an answer on June 12, 2026 at 3:23 am

    You pass betaRest to map. Map is (a -> a) -> [a] -> [a] so for [Int] list you pass it it wants an Int -> Int function. But partially applied betaRest is [Int] -> Int.

    As for [0..9] its type is (Enum t, Num t) => [t] and it’s translated into enumFromTo 0 9 application. So compiler figured your error the other way around: if you define special Num and Enum instances for lists, so [0..9] becomes a list of lists of int, then your application will make sense.

    But I think you want to use inits or tails function. Let us know what you want to achieve so we can help with solution.

    A minimal fix to would be to add prevDigits as an argument to map and use a lambda abstraction to ignore unused prevDigit:

       | otherwise = sum (map (\prevDigit -> betaRest (n - 1) [0..9]) prevDigits)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: canvas=new MembershipFunctionComponent(functions); canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight())); canvas.addMouseListener(canvas); pane.add(canvas); MembsershipFunctionComponent extends JComponent.
I have following code for opening all files: int ret= open(zFile, flags, mode); posix_fadvise
I have following code which is running fine, but I want to know if
I have following code: #include <cstring> #include <boost/functional/hash.hpp> #include <iostream> int main(int argc, char
I have following code: typedef int (*t_Function) (int x); t_Function Functions[MAX_FUNCTIONS]; int f(int x)
I have following code snippet in c# List<int> list = new List<int>() { 1,
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method

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.