Haskell - Definició de funcions d'ordre superior (1) P90677


Statement
 

pdf   zip

thehtml

Aquest problema explora la definició de funcions d’ordre superior sobre llistes. Implementeu les funcions següents mimetitzant les funcions originals de Haskell però sense usar la funció original (és a dir, no podeu usar foldl per implementar myFoldl però si per implementar myAll). A més, només podeu utilitzar recursivitat per definir myFoldl, myFoldr, myIterate, myUntil i myZip.

  1. myFoldl :: (a -> b -> a) -> a -> [b] -> a
  2. myFoldr :: (a -> b -> b) -> b -> [a] -> b
  3. myIterate :: (a -> a) -> a -> [a]
  4. myUntil :: (a -> Bool) -> (a -> a) -> a -> a
  5. myMap :: (a -> b) -> [a] -> [b]
  6. myFilter :: (a -> Bool) -> [a] -> [a]
  7. myAll :: (a -> Bool) -> [a] -> Bool
  8. myAny :: (a -> Bool) -> [a] -> Bool
  9. myZip :: [a] -> [b] -> [(a, b)]
  10. myZipWith :: (a -> b -> c) -> [a] -> [b] -> [c]

Puntuació

Cada funció puntua 10 punts.

Public test cases
  • Input

    myFoldl (+) 1 [1..5]
    myFoldr (+) 1 [1..5]
    take 10 $ myIterate (*2) 1
    myUntil (>100) (*2) 1
    myMap ("la "++) ["joana", "mireia"]
    myFilter odd [1..10]
    myAll odd [1,3,5,3,1]
    myAny odd [2,4,6,8,10]
    myZip [1..4] [1..3]
    myZipWith (+) [1..4] [1..3]
    

    Output

    16
    16
    [1,2,4,8,16,32,64,128,256,512]
    128
    ["la joana","la mireia"]
    [1,3,5,7,9]
    True
    False
    [(1,1),(2,2),(3,3)]
    [2,4,6]
    
  • Information
    Author
    Albert Rubio / Jordi Petit
    Language
    Catalan
    Other languages
    English
    Official solutions
    Haskell
    User solutions
    Haskell