Question

Hi everyone, I need help in Haskell, please. Write a Haskell function that takes an Int...

Hi everyone, I need help in Haskell, please.

Write a Haskell function that takes an Int i as its only parameter and uses a list comprehension to caclulate m(i) = 1 + 1/2 + 1/3, ... + 1/i

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

calc_m j = sum [1/i | i <- [1..j]]

main = do
print(calc_m 10)

Screenshot: ( for reference )

calc_m j = sum (1/i | i <- [1..]]] WN main = do print(calc_m 10)

Output:

2.9289682539682538

-----------------
Note: If you have any doubts please comment.

It will be great help If you like.

Add a comment
Know the answer?
Add Answer to:
Hi everyone, I need help in Haskell, please. Write a Haskell function that takes an Int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi everyone, I need help in Haskell Please 1) Write a function that takes a two-operand...

    Hi everyone, I need help in Haskell Please 1) Write a function that takes a two-operand integer function and a list of Ints, and applies the function to each in the list twice. it is OK to call the map in the function.

  • Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a...

    Hi everyone, I need help In Haskell Coding. Please code in Haskell, Regards 1) Write a function that takes a list of tuples of three integers each and returns a list consisting of just the tuples that are Pythagorean triples. instead of using a list comprehension, use lambda expression and a function that tests one tuple and returns a Bool. As long as the lambda expression is correct, it is OK to make this simpler by having the lambda calls...

  • Hi everyone, I need help in Haskell coding to please only Haskell code, Regards Consider this...

    Hi everyone, I need help in Haskell coding to please only Haskell code, Regards Consider this function: applyThrice f x = f (f (f x)) this function takes a unary function: for example: >applyThrice (+2) 2 8 use ., the function composition operator, and/or $, the function application operator, to make this function more readable

  • Hi Every one, hope all is well. I need help in Using Haskell coding Please, please...

    Hi Every one, hope all is well. I need help in Using Haskell coding Please, please read the instructon very carefully to: (in Syntax Code please) NOTE: function headers (for example, for the area-of-a-rectangle function, do not need to write area :: Int-> Int-> Int at the top of your function). You may use the :{ ... :} syntax to write multi-line functions in prelude Haskell platform. Write a function that takes three numbers, a b, and c, and returns...

  • Hi, I need help with Javascript please. Question: Write a function named "tweets" that takes a...

    Hi, I need help with Javascript please. Question: Write a function named "tweets" that takes a string as a parameter and returns the number of tweets required to tweet the input to the world. Note: The maximum length for a single tweet is 280 characters. Thanks!

  • Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes...

    Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes a key-value store as a parameter with strings as keys and integers as values. The function will add a key-value pair to the input store with a key of "slam" and a value of 39. There is no need to return any value. Thanks!

  • Hi, I need help with Python Dictionaries please. Question: Write a function named "get_stat" that takes...

    Hi, I need help with Python Dictionaries please. Question: Write a function named "get_stat" that takes a key-value store as a parameter with strings as keys and integers as values. The keys include "Strength", "Constitution", "Defense", "Dexterity", "Intelligence", "Charisma", "Willpower", and "Luck" and each value is an integer between 0 and 255. This function should return the value for the "Strength" stat. Thanks!

  • In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int...

    In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...

  • Programming Paradigms , using Haskell !!!! I need help on this problem , Intersection of list...

    Programming Paradigms , using Haskell !!!! I need help on this problem , Intersection of list of list HASKELL I need to use my own definition for intersection . Its my homework assignment. example like : intersection [ [2, 8, 6, 5, 8, 8, 8], [8, 8, 1, 1, 4, 8], [3, 3, 8, 10, 8, 10, 8, 7, 8, 8, 3]] Output: [8, 8, 8] intersection [ [1, 2, 3, 4], [5, 6, 7], [8], [9, 10]] Output: [...

  • IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x =...

    IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x = (x, f x) Using map and the function above, write a function that takes a list of Ints and a function (Int -> Int) and returns a new list of tuples, with the first element being the original element, and the second being the result of the transformation. e.g. [1,2,3] becomes [(1,1), (2, 4), (3, 9)] if the function passed in returns the square...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT