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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:27:06+00:00 2026-06-08T18:27:06+00:00

when I try to compile this piece of code prod [] = 1 prod

  • 0

when I try to compile this piece of code

prod [] = 1
prod (x:xs) = x * prod xs

ff :: (Num a) => a -> a -> a
ff x n = prod [(x - n + 1) .. x]

I get following error:

a.hs:5:15:
    Could not deduce (Enum a)
     arising from the arithmetic sequence `(x - n + 1) .. x'
    from the context (Num a)
      bound by the type signature for ff :: Num a => a -> a -> a
      at a.hs:5:1-32
    Possible fix:
      add (Enum a) to the context of
        the type signature for ff :: Num a => a -> a -> a
    In the first argument of `prod', namely `[(x - n + 1) .. x]'
    In the expression: prod [(x - n + 1) .. x]
    In an equation for `ff': ff x n = prod [(x - n + 1) .. x]

what is wrong with this code? When I substitute Double for a everything is all right.

  • 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-08T18:27:07+00:00Added an answer on June 8, 2026 at 6:27 pm

    [i .. j] is shorthand for enumFromTo i j. enumFromTo is part of the Enum typeclass, and not part of Num (you still need Num to use + and - though).

    So you need to say that a implements Enum as well as implementing Num:

    ff :: (Num a, Enum a) => a -> a -> a
    ff x n = prod [(x - n + 1) .. x]
    

    It works with Double because Double implements both these typeclasses.

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

Sidebar

Related Questions

When I try to compile this project I get the following error. I would
When I try to compile the piece of code below, I get this warning:
I have the following piece of code which doesn't compile when I try to
The following piece of code gives compile-time error in VS2010: Use of unassigned local
When I try to compile this code: struct BasicVertexProperties { Vect3Df position; }; struct
I'm getting a nothing to repeat error when I try to compile this: search
When I try compile with maven 3.0.4, Eclipse give me this error: Failed to
This Java code compiles fine, but when I try to run it I get:
I am having issues getting this piece of code to compile. I am compiling
I've got an enum like this in an old piece of code: [Flags] public

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.