Question

Use Ocaml language to writing function called warmups.ml Write this function in a pure functional style...

Use Ocaml language to writing function called warmups.ml Write this function in a pure functional style only: no assignment statements, no explicit loops, and no arrays!

Here are the problem you have to solve:

Write a new factorial function using pattern matching which is tail-recursive (i.e. it doesn't cause the stack to grow and there are no pending operations). You will need an internal helper function

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

ANSWER:

Below is the factorial function using helper function:


(defn helper [acc n]
(if (zero? n)
acc
(helper (* acc n) (dec n))))

(defn recurssive-factorial [n]
(helper 1 n))

Add a comment
Know the answer?
Add Answer to:
Use Ocaml language to writing function called warmups.ml Write this function in a pure functional style...
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
  • Use Ocaml language writing a bunch of simple functions in a file called warmups.ml. Write these...

    Use Ocaml language writing a bunch of simple functions in a file called warmups.ml. Write these functions in a pure functional style only: no assignment statements, no explicit loops, and no arrays! Write a function to compute fibonacci numbers (in the sequence 0, 1, 1, 2, 3, 5, ... where each number is the sum of the previous two numbers on the list). Use pattern matching but no if/then/else statements. Use a tail recursive solution to make sure the function...

  • Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to...

    Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to practice recursion. ignment: The assignment requires writing recursive methods for some linked list operations. The use of loops in the recursive methods is strictly prohibited in this assignment. That is, you cannot use for, while, and do-while in the recursive methods you will write. You can only use a loop when you will initiate values for a linked list in the main method. You...

  • Write a ML language function stripmin of type int list -> int list that will return...

    Write a ML language function stripmin of type int list -> int list that will return a list from which every instance of the lowest value has been removed. Hints: • Only stripmin itself should be visible at the top level; •You should have two recursive helper functions tucked away inside a let … in … end; structure • Also include a val to avoid having to pass a value that never changes to one of these functions. • Use...

  • Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make...

    Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make a word. This type of arrangement is generally referred to as an anagram, it's known as a permutation in mathematics. This assignment will give you some experience thinking about and writing recursive functions. Write a C++ program that searches for ``anagrams'' in a dictionary. An anagram is a word obtained by scrambling the letters of some string. For example, the...

  • Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of...

    Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of project offers only a few guidelines and requirements, allowing you to invest as much time, effort and imagination as you want.  Submit your java programs (*.java) and any other I/O (*.txt) via Canvas  You’ve worked quite hard to make it this far, so have a bit of fun with this project! Design Brief: Use Case Scenario You are hired to develop a...

  • In C++ Please!!!!! Example main: #include <iostream> #include <fstream> #include <istream> #include <cstring> using namespace std;...

    In C++ Please!!!!! Example main: #include <iostream> #include <fstream> #include <istream> #include <cstring> using namespace std; const int MAXRESULTS = 20; // Max matches that can be found const int MAXDICTWORDS = 30000; // Max words that can be read in int main() { string results[MAXRESULTS]; string dict[MAXDICTWORDS]; ifstream dictfile; // file containing the list of words int nwords; // number of words read from dictionary string word; dictfile.open("words.txt"); if (!dictfile) { cout << "File not found!" << endl; return...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

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
ADVERTISEMENT