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
| map (+1) [1, 2, 3, 4, 5] -- [2,3,4,5,6] | |
| map succ [1, 2, 3, 4, 5] -- [2,3,4,5,6] | |
| filter (>3) [1,5,3,2,1,6,4,3,2,1] -- [5,6,4] |
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
| -- hof.hs | |
| apply2 :: (a -> a) -> a -> a | |
| apply2 f x = f (f x) | |
| -- | |
| -- ghci hof.hs | |
| -- | |
| apply2 (*2) 100 -- 400 |
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
| map (\x -> x * 2) [1..4] -- [2,4,6,8] |
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
| def add(n:Int)(a:Int) = n + a | |
| val add2 = add(2)(_) | |
| add(5)(5) // 10 | |
| add2(30) // 32 |
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
| def benchmark(msg:String)(f:()=>Unit) = { | |
| val init = System.currentTimeMillis | |
| f | |
| val end = System.currentTimeMillis() | |
| println(msg + " in: " + (end - init) + " ms") | |
| } | |
| benchmark("for benchmark ")( () => | |
| for(i <- 1 to 1000){ | |
| println(i) |
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
| max 10 20 -- 20 | |
| (max 10) 20 -- 20 |
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
| -- currying.hs | |
| mul2 :: (Num a) => a -> a -> a | |
| mul2 x y = x * y | |
| -- | |
| -- ghci currying.hs | |
| -- | |
| mul2 2 3 -- 6 | |
| let double = mul2 2 |
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
| map (\x -> x + 3) [1,6,3,2] -- [4,9,6,5] | |
| map (\(a,b) -> a + b) [(1,2),(3,5),(6,3),(2,6),(2,5)] -- [3,8,9,8,7] | |
| -- add.hs | |
| addThree :: (Num a) => a -> a -> a -> a | |
| addThree = \x -> \y -> \z -> x + y + z | |
| -- | |
| -- ghci add.hs |
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
| () => 2 +2 // () => Int = <function0> | |
| (() => 2 + 2)() // 4 | |
| List(1,2,3,4,5).map( i => i + 1 ) // List(2, 3, 4, 5, 6) | |
| List(1,2,3,4,5,6,7,8,9,10).filter( n => n >= 7 ) // List(7, 8, 9, 10) | |
| List(1,2,3,4,5,6,7,8,9,10).filter( _ >= 7 ) // List(7, 8, 9, 10) |
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
| cd / | |
| mkdir /home/diegopacheco | |
| echo "export HOME=/home/diegopacheco" >>.bashrc | |
| echo "export HOME=/home/diegopacheco" >>.bash_profile | |
| cp .bashrc .bash_profile /home/diegopacheco | |
| echo "cd" >>.bashrc |