Question: Write the codes in HASKELL. 1. Recall that the function combinations takes a list of elements of typeclass Ord and an integer k as its
Write the codes in HASKELL.
1. Recall that the function combinations takes a list of elements of typeclass Ord and an integer k as its arguments and returns a list of
length k lists representing all possible subsets of size k. The function splits is similar, except that, given a list of elements of length n, it returns a list of
pairs of lists. The first component of the pair represents a combination of length k. The second component represents the complementary combination of length n?k. Two combinations are complementary when their union is equal to the original list. Write splits.
For example:
*Main> :t splits splits :: (Ord a) => [a] -> [([a], [a])]
*Main> splits "abc"
[("c","ab"),("b","ac"),("bc","a"),("a","bc"),("ac","b"),("ab","c")]
2. The function argmin takes a function f and a list xs as arguments and returns the element of the list x such that f applied to x has minimum value. Write argmin.
For example:
*Main> :t argmin
argmin :: (Ord a) => (t -> a) -> [t] -> t
*Main> argmin length ["ABC","EF","GHIJ","K"]
"K"
Thank you.
n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
