Define these functions in SML Language with using  the standard functions abs and length, and the Int.toString function, Predefined functions: real, floor, ceil, round, trunc, ord, chr, str, hd, tl, explode, implode, and null   dont use pattern matching to solve the function

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Define these functions in SML Language with using  the standard functions abs and length, and the Int.toString function, Predefined functions: real, floor, ceil,
round, trunc, ord, chr, str, hd, tl,
explode, implode, and null

 

dont use pattern matching to solve the function

1. Define a function called pow (val pow = fn: int * int -> int) that takes two integers as arguments and that returns the result of raising the first integer to the power of the
second. You may assume that the power is not negative. For our purposes, we will assume that every integer to the 0 power is 1 (this isn't true of 00, but that's okay).
2. Define a function called sumTo (val sumTo = fn : int -> real) that accepts an integer n and that computes the sum of the first n reciprocals. For example, sumTo(3) should
return (1 + 1/2 + 1/3) = 1.83333333.... The function should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n.
3. Define a function called repeat (val repeat = fn : string * int -> string) that takes a string and an integer (>= 0) as arguments and that returns a string composed of the
given number of occurrences of the string. For example, repeat("hello", 3) returns "hellohellohello", repeat("hello", 0) returns "". You may assume that the function is not
passed a negative value for the second argument.
4. Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary
representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than
16 bits. Note: If needed, you can use the Int.toString function to convert integers to corresponding strings. You may find it helpful to write a helper function for this
problem.
5. Define a function called countNegative (val countNegative = fn : int list -> int) that takes a list of integers as an argument and that returns a count of the number of
negative integers in the list. For example, countNegative([3,17,-9,34,-7,2]) should return 2.
6. Define a function called absList (val absList = fn : (int * int) list -> (int * int) list) that takes a list of int * int tuples and that returns a new list of int * int tuples where every
integer is replaced by its absolute value. For example, absList([(~38,47), (983,~14), (~17,~92), (0,34)]) should return [(38,47), (983,14), (17,92), (0,34)]. HINT: This is
easier to solve if you write a helper function to process one tuple.
7. Define a function called split (val split = fn : int list -> (int * int) list) that takes a list of integers as an argument and that returns a list of the tuples obtained by splitting each
integer in the list. Each integer should be split into a pair of integers whose sum equals the integer and which are each half of the original. For odd numbers, the second
value should be one higher than the first. For example, split([5,6,8,17,93,0]) should return [(2,3), (3,3), (4,4), (8,9), (46,47), (0,0)]. You may assume that all of the integers
in the list passed to the function are greater than or equal to 0.
8. Define a function called is Sorted (val isSorted = fn : int list -> bool) that takes a list of integers and that returns whether or not the list is in sorted (nondecreasing) order
(true if it is, false if it is not). By definition, the empty list and a list of one element are considered to be sorted.
Transcribed Image Text:1. Define a function called pow (val pow = fn: int * int -> int) that takes two integers as arguments and that returns the result of raising the first integer to the power of the second. You may assume that the power is not negative. For our purposes, we will assume that every integer to the 0 power is 1 (this isn't true of 00, but that's okay). 2. Define a function called sumTo (val sumTo = fn : int -> real) that accepts an integer n and that computes the sum of the first n reciprocals. For example, sumTo(3) should return (1 + 1/2 + 1/3) = 1.83333333.... The function should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n. 3. Define a function called repeat (val repeat = fn : string * int -> string) that takes a string and an integer (>= 0) as arguments and that returns a string composed of the given number of occurrences of the string. For example, repeat("hello", 3) returns "hellohellohello", repeat("hello", 0) returns "". You may assume that the function is not passed a negative value for the second argument. 4. Define a function called binary (val binary = fn: int -> string) that takes an integer n as an argument and returns a string corresponding to the 16-bit binary representation of that integer. For example, binary 17 returns "0000000000010001". You need not account for numbers whose binary representation requires more than 16 bits. Note: If needed, you can use the Int.toString function to convert integers to corresponding strings. You may find it helpful to write a helper function for this problem. 5. Define a function called countNegative (val countNegative = fn : int list -> int) that takes a list of integers as an argument and that returns a count of the number of negative integers in the list. For example, countNegative([3,17,-9,34,-7,2]) should return 2. 6. Define a function called absList (val absList = fn : (int * int) list -> (int * int) list) that takes a list of int * int tuples and that returns a new list of int * int tuples where every integer is replaced by its absolute value. For example, absList([(~38,47), (983,~14), (~17,~92), (0,34)]) should return [(38,47), (983,14), (17,92), (0,34)]. HINT: This is easier to solve if you write a helper function to process one tuple. 7. Define a function called split (val split = fn : int list -> (int * int) list) that takes a list of integers as an argument and that returns a list of the tuples obtained by splitting each integer in the list. Each integer should be split into a pair of integers whose sum equals the integer and which are each half of the original. For odd numbers, the second value should be one higher than the first. For example, split([5,6,8,17,93,0]) should return [(2,3), (3,3), (4,4), (8,9), (46,47), (0,0)]. You may assume that all of the integers in the list passed to the function are greater than or equal to 0. 8. Define a function called is Sorted (val isSorted = fn : int list -> bool) that takes a list of integers and that returns whether or not the list is in sorted (nondecreasing) order (true if it is, false if it is not). By definition, the empty list and a list of one element are considered to be sorted.
de il it is, raise II TU
ol). By de nition, the empty list and a list of one element are considered to be sorted.
9. Define a function called collapse (val collapse = fn : int list -> int list) that takes a list of integers as an argument and that returns the list obtained by collapsing successive
pairs in the original list by replacing each pair with its sum. For example, collapse([1,3,5,19,7,4]) should return [4,24,11] because the first pair (1 and 3) is collapsed into its
sum (4), the second pair (5 and 19) is collapsed into its sum (24) and the third pair (7 and 4) is collapsed into its sum (11). If the list has an odd length, the final number in
the list is not collapsed. For example, collapse([1,2,3,4,5]) should return [3,7,5].
10. Define a function called insert (val insert = fn : int * int list -> int list) that takes an integer and a sorted (nondecreasing) integer list as parameters and that returns the list
obtained by inserting the integer into the list so as to preserve sorted order. For example, insert(8,[1,3,7,9,22,38]) should return [1,3,7,8,9,22,38].
11. Define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For
example, decimal "10001" returns 17, decimal "001101" returns 13.
Transcribed Image Text:de il it is, raise II TU ol). By de nition, the empty list and a list of one element are considered to be sorted. 9. Define a function called collapse (val collapse = fn : int list -> int list) that takes a list of integers as an argument and that returns the list obtained by collapsing successive pairs in the original list by replacing each pair with its sum. For example, collapse([1,3,5,19,7,4]) should return [4,24,11] because the first pair (1 and 3) is collapsed into its sum (4), the second pair (5 and 19) is collapsed into its sum (24) and the third pair (7 and 4) is collapsed into its sum (11). If the list has an odd length, the final number in the list is not collapsed. For example, collapse([1,2,3,4,5]) should return [3,7,5]. 10. Define a function called insert (val insert = fn : int * int list -> int list) that takes an integer and a sorted (nondecreasing) integer list as parameters and that returns the list obtained by inserting the integer into the list so as to preserve sorted order. For example, insert(8,[1,3,7,9,22,38]) should return [1,3,7,8,9,22,38]. 11. Define a function called decimal (val decimal = fn: string -> int) that takes a bit string corresponding to an integer and returns the decimal value of that integer. For example, decimal "10001" returns 17, decimal "001101" returns 13.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Algebraic Expression
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education