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.
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 by step
Solved in 4 steps with 6 images