Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Write a code (and explain your code) in ML Programming Language Define a func

ID: 3711755 • Letter: 7

Question

7. Write a code (and explain your code) in ML Programming Language
Define a function first_list : (‘a * ‘b) list -> ‘a list which takes in input a list of pairs and gives back the list consisting of the first elements only, Examples:
first_list [ ] = [ ] first_list [ (1,2), (1,3) ] = [ 1,1]
first_list [ (1, “a”), (2,”b”), (3, “c”) ] = [ 1,2,3 ]
first_list [ ( [ ] , “a”) , ( [ 1 ] , “b”) , ( [ 1,2 ] , “c”) ] = [ [ ] , [ 1] , [ 1,2 ] ]
7. Write a code (and explain your code) in ML Programming Language
Define a function first_list : (‘a * ‘b) list -> ‘a list which takes in input a list of pairs and gives back the list consisting of the first elements only, Examples:
first_list [ ] = [ ] first_list [ (1,2), (1,3) ] = [ 1,1]
first_list [ (1, “a”), (2,”b”), (3, “c”) ] = [ 1,2,3 ]
first_list [ ( [ ] , “a”) , ( [ 1 ] , “b”) , ( [ 1,2 ] , “c”) ] = [ [ ] , [ 1] , [ 1,2 ] ]
7. Write a code (and explain your code) in ML Programming Language
Define a function first_list : (‘a * ‘b) list -> ‘a list which takes in input a list of pairs and gives back the list consisting of the first elements only, Examples:
first_list [ ] = [ ] first_list [ (1,2), (1,3) ] = [ 1,1]
first_list [ (1, “a”), (2,”b”), (3, “c”) ] = [ 1,2,3 ]
first_list [ ( [ ] , “a”) , ( [ 1 ] , “b”) , ( [ 1,2 ] , “c”) ] = [ [ ] , [ 1] , [ 1,2 ] ]

Define a function first_list : (‘a * ‘b) list -> ‘a list which takes in input a list of pairs and gives back the list consisting of the first elements only, Examples:
first_list [ ] = [ ] first_list [ (1,2), (1,3) ] = [ 1,1]
first_list [ (1, “a”), (2,”b”), (3, “c”) ] = [ 1,2,3 ]
first_list [ ( [ ] , “a”) , ( [ 1 ] , “b”) , ( [ 1,2 ] , “c”) ] = [ [ ] , [ 1] , [ 1,2 ] ]

Explanation / Answer

Answer:

ML Code for the given question:

fun first_list [] = []

| first_list((x,y)::1) = x::first_list 1;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote