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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:07:48+00:00 2026-06-13T05:07:48+00:00

I am trying to write the power series in Haskell, e^x = 1 +

  • 0

I am trying to write the power series in Haskell,

e^x = 1 + x + x^2/2! + x^3/3! + ...

such that it will out put

[1,1,1/2,1/6,...]

so far I got:

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

powerSrs x = 1 : powerSrsFunc[1..] where
        powerSrsFunc ( p: xs ) = 
            p : powerSrsFunc[y | y <-xs, ( (x^y) / (factorial y) )]

However, I understand that my typing here is wrong. I am getting this error:

tut08.hs:8:58:
    No instance for (Integral Bool)
      arising from a use of `^'
    Possible fix: add an instance declaration for (Integral Bool)
    In the first argument of `(/)', namely `(x ^ y)'
    In the expression: ((x ^ y) / (factorial y))

    In a stmt of a list comprehension: ((x ^ y) / (factorial y))

tut08.hs:8:62:
    No instance for (Fractional Bool)
      arising from a use of `/'
    Possible fix: add an instance declaration for (Fractional Bool)
    In the expression: ((x ^ y) / (factorial y))
    In a stmt of a list comprehension: ((x ^ y) / (factorial y))
    In the first argument of `powerSrsFunc', namely
      `[y | y <- xs, ((x ^ y) / (factorial y))]'

1) How do you write fractions in Haskell such that it is output like ‘1/2’?

2) What does it mean when they say No instance for (Integral Bool) and (Fractional Bool)?

Is it referring to two arguments that are of type Integral and Bool?

Does it not take Integral and Integral?

  • 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-13T05:07:49+00:00Added an answer on June 13, 2026 at 5:07 am

    In list comprehension syntax you have three main parts. Taking your code as example

    [y | y <-xs, ( (x^y) / (factorial y) )]
    

    Beginning from the left, you have what each element in the resulting list should be. In your case, simply y. After the pipe character (|) you continue by specifying how to iterate over the input list. In English “for each y in xs”.

    The last part, and your problem, is the filters. You can put a comma separated list of conditions that all need to be true for the list comprehension not to filter out the current y. Instead of putting a condition there (something that is true or false) you put an expression there that results in a number. However, I assume you dont actually want to filter on anything. Rather, you want to output the result of that expression. So it needs to be to the left of the pipe character.

    [(x^y) / (factorial y) | y <-xs]
    

    As far as displaying rational numbers, take a look at the Data.Ratio package http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Ratio.html

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

Sidebar

Related Questions

I'm trying to write a method that will compute all permutations of a power
Continuing from the previous question: Power Series in Haskell I am trying to write
Trying to write app for service technicians that will display open service calls within
Trying to write a couple of functions that will encrypt or decrypt a file
I'm trying to write a function that will take an array on input and
I'm trying to write a PowerShell script that will automate my IIS website deployments.
I'm trying to write a small app that monitors how much power is left
I've been trying to write a program in C++ that will monitor running processes
I am trying to write a tail-recursive function poly that will compute the value
I m trying write code that after reset set up rrpmax as 3000. It

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.