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
type Rand[+A] = RNG => (A, RNG) |
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 nextInt: (Int, RNG) = { | |
val newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL | |
val nextRNG = SimpleRNG(newSeed) | |
val n = (newSeed >>> 16).toInt | |
(n, nextRNG) | |
} |
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
length(List (5,6,7)) | |
foldRight(5 :: 6 :: 7 :: Nil, 0) ((_, acc) => acc + 1) | |
f(5, foldRight(6 :: 7 :: Nil, 0) ((_, acc) => acc + 1)) | |
(foldRight(6 :: 7 :: Nil, 0) ((_, acc) => acc + 1)) + 1 | |
(f(6, foldRight(7 :: Nil, 0)) ((_, acc) => acc + 1))) + 1 | |
((foldRight(7 :: Nil, 0) ((_, acc) => acc + 1)) + 1) + 1 | |
(((0 + 1) + 1) + 1) |
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
foldRight(Cons(1, Cons(2, Cons(3, Nil))), Nil:List[Int]) (Cons(_,_)) | |
Cons(1, foldRight(Cons(2, Cons(3, Nil)), Nil:List[Int]) (Cons(_,_))) | |
Cons(1, Cons(2, foldRight(Cons(3, Nil), Nil:List[Int]) (Cons(_,_)))) | |
Cons(1, Cons(2, Cons(3, foldRight(Nil, Nil:List[Int]) (Cons(_,_))))) | |
Cons(1, Cons(2, Cons(3, Nil))) | |
List(1,2,3,Nil) |
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
foldLeft(List(10.0,23.0,96.0), 1.0) (_ * _) | |
foldLeft(10.0 :: 23.0 :: 96.0 :: Nil, 1.0) (_ * _) | |
foldLeft(23.0 :: 96.0 :: Nil, (1.0 * 10.0)) (_ * _) | |
foldLeft(96.0 :: Nil, ((1.0 * 10.0) * 23.0)) (_ * _) | |
foldLeft(Nil, (((1.0 * 10.0) * 23.0) * 96.0)) (_ * _) | |
(((1.0 * 10.0) * 23.0) * 96.0) |
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
foldLeft(List(1,2,3), 0) (_ + _) | |
foldLeft(1 :: 2 :: 3 :: Nil, 0) (_ + _) | |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) | |
foldLeft(3 :: Nil, ((0 + 1) + 2)) (_ + _) | |
foldLeft(Nil, (((0 + 1) + 2) + 3)) (_ + _) | |
(((0 + 1) + 2) + 3) |
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
foldLeft(List(1,2,3), 0) (_ + _) | |
foldLeft(1 :: 2 :: 3 :: Nil, 0) (_ + _) | |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) | |
foldLeft(3 :: Nil, ((0 + 1) + 2)) (_ + _) | |
foldLeft(Nil, (((0 + 1) + 2) + 3)) (_ + _) |
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
foldLeft(List(1,2,3), 0) (_ + _) | |
foldLeft(1 :: 2 :: 3 :: Nil, 0) (_ + _) | |
foldLeft(2 :: 3 :: Nil, f(0, 1)) (_ + _) | |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) | |
foldLeft(3 :: Nil, ((0 + 1) + 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
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) |
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
foldLeft(List(1,2,3), 0) (_ + _) // step 1 - where we start | |
foldLeft(1 :: 2 :: 3 :: Nil, 0) (_ + _) // micro-step 1(a) | |
foldLeft(2 :: 3 :: Nil, f(0, 1)) (_ + _) // micro-step 1(b) | |
foldLeft(2 :: 3 :: Nil, (0 + 1)) (_ + _) // step 2 - where we end up |