19. HaskellEvalPerezosa

19. HaskellEvalPerezosa - Lenguajes de programacin...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 ]
Background image of page 2
Ejemplo Filtrar una lista de números
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

19. HaskellEvalPerezosa - Lenguajes de programacin...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online