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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:03:56+00:00 2026-06-08T06:03:56+00:00

I am trying to implement a tail recursive version of factorial: let{factorial 0 n

  • 0

I am trying to implement a tail recursive version of factorial:

let{factorial 0 n = n; factorial x n =  factorial (x-1, n * x)}

I get this:

<interactive>:1:41:
Occurs check: cannot construct the infinite type: t1 = t1 -> t1
In the return type of a call of `factorial'
In the expression: factorial (x - 1, n * x)
In an equation for `factorial':
    factorial x n = factorial (x - 1, n * x)

<interactive>:1:52:
Occurs check: cannot construct the infinite type: t0 = (t0, t1)
In the first argument of `(-)', namely `x'
In the expression: x - 1
In the first argument of `factorial', namely `(x - 1, n * x)'

<interactive>:1:61:
Occurs check: cannot construct the infinite type: t1 = (t0, t1)
In the second argument of `(*)', namely `x'
In the expression: n * x
In the first argument of `factorial', namely `(x - 1, n * x)'

How am i constructing an infinite type here? (using GHCi 7.0.1)

  • 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-08T06:03:58+00:00Added an answer on June 8, 2026 at 6:03 am

    I’m not a strong Haskell programmer, but I think you want to rewrite

    factorial x n =  factorial (x-1, n * x)
    

    as

    factorial x n =  factorial (x-1) (n * x)
    

    Since (x-1, n * x) is a pair type, which isn’t what you want.

    Hope this helps!

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

Sidebar

Related Questions

I´ve been trying to implement a tail-recursive version of chainl1, but even with the
I’m trying to implement a tail-recursive list-sorting function in OCaml, and I’ve come up
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm making a linked list class and am trying to implement this contains() method.
I've tried to make an iterative/tail-recursive version of a function to compute the n
I'm using Visual c++. I'm trying to implement a circular buffer, this CB must
Trying to implement AVAudioplayer and get some metering data of the played music, but
I'm trying to implement a ring buffer with the following struct /*head, tail are
I am trying to implement the scala splitAt using pattern matching and this is
I'm trying implement A* Start path finding in my games(which are written with JavaScript,

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.