Write functions in the following exercises, for example, the function for cube of type int -> int that returns the cube of its parameter is: fun cube x = x*x*x. Exercise 3 Write a function fourth of type 'a list -> 'a that returns the fourth element of a list. Your function need not behave well on lists with less than four elements. Exercise 6 Write a function thirds of type string -> char that returns the third character of a string. Your function need not behave well on strings with lengths less than 3. Exercise 9 Write a function de 13 of type 'a list -> 'a list whose output list is the same as the input list, but with the third element deleted. Your function need not behave well on lists with lengths less than 3.

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
100%
Write functions in the following exercises, for example, the function for cube of type int ->
int that returns the cube of its parameter is: fun cube x = x*x*x.
Exercise 3 Write a function fourth of type 'a list -> 'a that returns the
fourth element of a list. Your function need not behave well on lists with less than
four elements.
Exercise 6 Write a function thirds of type string -> char that returns
the third character of a string. Your function need not behave well on strings with
lengths less than 3.
Exercise 9 Write a function de 13 of type 'a list -> 'a list whose output
list is the same as the input list, but with the third element deleted. Your function
need not behave well on lists with lengths less than 3.
Transcribed Image Text:Write functions in the following exercises, for example, the function for cube of type int -> int that returns the cube of its parameter is: fun cube x = x*x*x. Exercise 3 Write a function fourth of type 'a list -> 'a that returns the fourth element of a list. Your function need not behave well on lists with less than four elements. Exercise 6 Write a function thirds of type string -> char that returns the third character of a string. Your function need not behave well on strings with lengths less than 3. Exercise 9 Write a function de 13 of type 'a list -> 'a list whose output list is the same as the input list, but with the third element deleted. Your function need not behave well on lists with lengths less than 3.
Expert Solution
Step 1

Algorithm: Exercise 3

Step 1 Start.
Step 2 Define a function named fourth that takes a list lst as an argument.
Step 3 Return the element at index 3 of the input list lst.
Step 4 End of function.
Step 5 Create a list lst with six integers in it.
Step 6 Call the fourth function with lst as its argument and print the returned value.
Step 7 End.

 

Algorithm: Exercise 6

Step 1 Start.

Step 2 Define a function named "thirds" that takes a string as an argument.

Step 3 Return the character in the third position of the input string.

Step 4 Assign a string "Hello World" to a variable named "string".

Step 5 Call the "thirds" function and pass "string" as an argument.

Step 6 Print the returned value.

Step 7 End.

 

Algorithm: Exercise 9

Step 1 Start.

Step 2 Define a function called "de_13" that takes a list as an argument.

Step 3 Within the function, delete the element at index 2 in the list using the "del" statement.

Step 4 Return the modified list.

Step 5 Outside the function, create a list called "lst" with six integer elements.

Step 6 Call the "de_13" function with the "lst" list as an argument and print the returned value.

Step 7 End.
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Arrays
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
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