Práctica 0 (Paradigmas)

De Cuba-Wiki
Revisión del 04:41 5 sep 2021 de Dave (discusión | contribs.) (Practica 0 - Haskell)
(difs.) ← Revisión anterior | Revisión actual (difs.) | Revisión siguiente → (difs.)

Ejercicio 1

Dar el tipo y describir el comportamiento de las siguientes funciones del m ́odulo Prelude de Haskell: null head tail init last take drop (++) concat (!!) elem

"null returns True if a list is empty, otherwise False"

null :: forall (t :: * -> *) a. Foldable t => t a -> Bool "head returns first elemt of list"

head :: forall a. [a] -> a "tail returns list without head"

tail :: forall a. [a] -> [a] "init returns a list withou the last item"

init :: forall a. [a] -> [a] "last returns the last items"

last :: forall a. [a] -> a "take return the first n items" take :: forall a. Int -> [a] -> [a] "drop removes the first n items"

drop :: forall a. Int -> [a] -> [a] "(++) concats lists"

(++) :: forall a. [a] -> [a] -> [a] "concat accepts a list of lists and concatenates them"

concat :: forall (t :: * -> *) a. Foldable t => t [a] -> [a] "(!!) List index (subscript) operator, starting from 0"

(!!) :: forall a. [a] -> Int -> a "returns True if the list contains an item equal to the first argument"

elem :: forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool