# 19. HaskellEvalPerezosa - Lenguajes de programacin...

This preview shows pages 1–4. Sign up to view the full content.

Lenguajes de programación Evaluación Perezosa y otras monerías en Haskel monerías en Haskell “Guardias” Se usan en definiciones por casos Ejemplo: fact1 :: Int -> Int fact1 n -- usa “guardias” | n == 0 = 1 | n > 0 = n * fact1 (n-1) fact2 :: Int -> Int fact2 0 = 1 -- usa pattern matching fact2 (n+1) = (n+1) * fact2 n

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Ejemplo Extraer los números pares de una Extraer los números pares de una lista getEven [1. .10] => [2,4,6,8,10] getEven :: [Int] -> [Int] tE [] [] getEven [] = [] getEven (x:xs) | even x = x : getEven xs | otherwise = getEven xs Comprensión de listas [fx|x<- xs ] significa la lista [ f x | x < xs ] significa la lista de todas las f x tales que x pertenece a xs x <- xs es denominado un generador Ejemplo: producto cartesiano prodcart [1,2] [3,4] => [(1,3),(1,4),(2,3),(2,4)] prodcart :: [a] -> [b] -> [(a, b)] prodcart xs ys = [ (x,y) | x <- xs, y <- ys ]
Ejemplo Filtrar una lista de números

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

19. HaskellEvalPerezosa - Lenguajes de programacin...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online