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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:44:32+00:00 2026-06-01T16:44:32+00:00

I was so sleepy that I wrote the following code (modified to just show

  • 0

I was so sleepy that I wrote the following code (modified to just show the confusion):

fac s = take 10 [s, s `mod` 1 ..]

maxFactor x = if (s == [])
              then x
              else head    <-- this should be 'head x' instead of just 'head'
  where s = fac x

However, this load into ghci (and compiles) just fine. When I executed maxFactor 1, it complains (of course):

<interactive>:0:1:
    No instance for (Integral ([a0] -> a0))
      arising from a use of `maxFactor'
    Possible fix:
      add an instance declaration for (Integral ([a0] -> a0))
    In the expression: maxFactor 1
    In an equation for `it': it = maxFactor 1

<interactive>:0:11:
    No instance for (Num ([a0] -> a0))
      arising from the literal `1'
    Possible fix: add an instance declaration for (Num ([a0] -> a0))
    In the first argument of `maxFactor', namely `1'
    In the expression: maxFactor 1
    In an equation for `it': it = maxFactor 1

However, I don’t understand this behavior:

fac‘s type is:

fac :: Integral a => a -> [a]

while maxFactor‘s type is:

maxFactor :: Integral ([a] -> a) => ([a] -> a) -> [a] -> a

Doesn’t this mean the following:

  1. the first input to fac must be of typeclass Integral (e.g., fac 10);
  2. since in the definition of maxFactor, there is fac x, x must also be of typeclass Integral, thus, maxFactor‘s type would be begin with something like maxFactor :: (Integral a) => a ->… then something else? However, if that is the case, then why this code compiles since the return of maxFactor can be x or head, which when following this line of reasoning, does not have the same type?

What am I missing here?

Thanks for any inputs in advance!

  • 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-01T16:44:33+00:00Added an answer on June 1, 2026 at 4:44 pm

    in maxFactor the compiler infers that the function argument x necessarily has the same type as head (in your if clause). Since you also call fac on x (which in turn calls mod) it infers that x is also some Integral class type. Consequently, the compiler infers the type

    maxFactor :: Integral ([a] -> a) => ([a] -> a) -> [a] -> a
    

    that takes some head-like and integer-like argument… which is unlikely to be a real thing.

    I think the fact that you can load that code into GHCi is more a quirk of the interpreter. If you were just compiling the code above, it would fail.

    Edit: I guess the issue is that the type checker can make sense of your code, however there probably isn’t any sensible way to use it.

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

Sidebar

Related Questions

Consider the following code: while(true) { someFunction(); Thread.sleep(1000); } What I want is that,
all. I wrote the following simple code to test scala.actors._: // java version 1.7.0_02
I have the following python code that expects data coming from the serial port,
I made a program that opens an application, sleeps the thread for 500ms then
Can we use sleep function at applicationDidFinishLaunching to take more time to show Splash
I have a quite simple perl script, that in one function does the following:
I have the following python code: import pty import subprocess os=subprocess.os from subprocess import
I am experiencing difficulty with the following VBS code. It works only sometimes, and
I have this following code fragment which is accessed by different threads. try {
Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?

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.