Skip to content

Instantly share code, notes, and snippets.

@juanbono
Last active June 1, 2016 14:30
Show Gist options
  • Save juanbono/45f81fb3daa542f8fcec52497041d05e to your computer and use it in GitHub Desktop.
Save juanbono/45f81fb3daa542f8fcec52497041d05e to your computer and use it in GitHub Desktop.
Ejemplos de uso de expresiones lambda
-- 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