Haskell — Definition of higher-order functions (2)

This problem explores the definition of higher-order functions on lists.

  1. Define a function countIf :: (Int -> Bool) -> [Int] -> Int that, given a predicate on integers and a list of integers, returns the number of elements in the list that satify the predicate.

  2. Define a function pam :: [Int] -> [Int -> Int] -> [[Int]] that, given a list of integers and a list of functions from integers to integers, returns the list consisting if applying each of the functions in the second list to the elements in the first list.

  3. Define a function pam2 :: [Int] -> [Int -> Int] -> [[Int]] that, given a list of integers and a list of functions from integers to integers, returns the list of lists where each list if the result of applying, one after the other, the function in the second list to each element in the first list.

  4. Define a function filterFoldl :: (Int -> Bool) -> (Int -> Int -> Int) -> Int -> [Int] -> Int that returns a fold of all the elements that satisfy the given predicate.

  5. Define a function insert :: (Int -> Int -> Bool) -> [Int] -> Int -> [Int] that, given a relation between integers, a list and un element, return the list with the inserted element according to the relation.

    Use function insert, in order to define function insertionSort :: (Int -> Int -> Bool) -> [Int] -> [Int] that orders a list according to the given relation.

Scoring

Each item scores 20 points.

Problem information

Author: Unknown
Translator: Jordi Petit

Generation: 2026-02-03T17:01:28.696Z

© Jutge.org, 2006–2026.
https://jutge.org