Question: PLEASE READ!!!! please have the code in Ocaml not Python. Part 1 : Non - Recursive Functions Implement the following functions that do not require

PLEASE READ!!!! please have the code in Ocaml not Python.
Part 1: Non-Recursive Functions
Implement the following functions that do not require recursion. Accordingly, these functions are defined
without the rec keyword, but you MAY add the rec keyword to any of the following functions or write a
recursive helper function. Just remember that if you write a helper function, it must be defined in the file
before it is called.
rev_tup (tup:('a *'b))
Type: 'a *'b *'c ->'c *'b *'a
Description: Returns a tuple in the reverse order of tup .
Examples:
revtup(1,2)=(2,1)
revtup(1,1)=(1,1)
rev+tup(a,1)=(1,a)
rev_triple (triple:('a *'b *'c ))
Type: 'a *'b *'c ->'c *'b *'a
Description: Returns a triple in the reverse order of triple .
Examples:
revtriple((1,2,3))=(3,2,1)
revtriple((1,1,1))=(1,1,1)
revtriple((a,1,c))=(c,1,a)
is_odd(x:int)
Type: int -> bool
Description: Returns whether or not x is odd.
Examples:
isodd1= true
isodd4= false
isodd9= true is_older(date1 :(int * int * int), date2:(int * int * int))
Type: (int * int * int)->(int * int * int)-> bool
Description: Returns whether date1 comes before the date2.
Examples:
is_older (2021,1,15),(2020,1,16)= false
is_older (2022,1,15),(2021,2,16)= false
is_older (2022,1,16),(2021,2,1)= false
is_older (2021,1,14),(2021,1,15)= true
to_us_format(date1 :(int * int * int)
Type: (int * int * int)->(int * int * int)
Description: Convert date which appears as (Year, Month, Day) to US format (Month, Day, Year).
Examples:
to_us_format (2021,1,15)=(1,15,2021)
to_us_format (2022,1,15)=(1,15,2022)
to_us_format (2022,10,16)=(10,16,2022)
to_us_format (2021,12,6)=(12,6,2021)
Part 2: Recursive Functions
Implement the following functions using recursion.
pow (x:int, p:int)
Type: int -> int -> int
Description: Returns x raised to the power p .
Assumptions: p is non-negative, and we will not test your code for integer overflow cases.
Examples:
pow 3,1=3
pow 3,2=9
pow (-3),3=-27
fac (x:int)
Type: int -> int
Description: Returns the factorial of x as an integer.
Assumptions: You may assume the answer is non-negative, x1.
Examples:
fac 4=24
fac 5=120
fac 7=5040
fac 2=2
get_nth ((idx : int),(lst: 'a list))
Type: int -> 'a list ->'a
Description: Returns the element at the index idx in the list lst.
Assumptions: idx is non-negative.
Examples:
README
getnth2,[26;11;99]=99
getnth0,[a; b]=a
getnth1[a; b]=b
larger ((lst1: 'a list),(lst2: 'a list))
Type: 'a list -> 'a list -> 'a list
Description: Returns the longer list provided as an argument, returns the
empty list if the two lists are the same length.
Examples:
larger [][]=[]
larger [1][2;3]=[2;3]
larger [2;4][2]=[2;4]
larger [4;1;2][3;5;7]=[]
sum((lst1: int list),(lst12: int list))
PLEASE READ!!!! please have the code in Ocaml not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!