Last active
June 1, 2016 14:30
-
-
Save juanbono/45f81fb3daa542f8fcec52497041d05e to your computer and use it in GitHub Desktop.
Ejemplos de uso de expresiones lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Ejemplos de expresiones lambda | |
sumar1 :: Num a => a -> a | |
sumar1 x = x + 1 | |
sumar1ConLambda :: Num a => a -> a | |
sumar1ConLambda = \x -> x + 1 | |
noUsoArgs :: a -> b -> c -> Integer | |
noUsoArgs = \x y z -> 2 -- (\x y z -> 2) Devuelve 2 para toda combinacion de parametros. | |
agregarCorchetes :: String -> String | |
agregarCorchetes s = "[" ++ s ++ "]" | |
f :: Integer -> String | |
f = agregarCorchetes . show . (+1) | |
fLambda :: Integer -> String | |
fLambda = (\s -> "[" ++ s ++ "]") . (\x -> show (x + 1)) | |
fLambda2 :: Integer -> String | |
fLambda2 = agregarCorchetes . (\x -> (show . (+1)) x) | |
aplicarTodas :: b -> [(b -> b)] -> b | |
aplicarTodas e lista = foldl (\x f -> f x) e lista | |
-- Ejemplo de aplicacion: aplicarTodas 1 [(\x -> x + 1), (\x -> x * 2), (\x -> x * x)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment