Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[info] Loading project definition from /home/shigemk2/projects/github.com/shigemk2/fpinscala/project
[info] Set current project to fpinscala (in build file:/home/shigemk2/projects/github.com/shigemk2/fpinscala/)
>  (reverse-i-search)`':  (reverse-i-search)`a': answers/console (reverse-i-search)`an': answers/console (reverse-i-search)`ans': answers/console (reverse-i-search)`answ': answers/console (reverse-i-search)`answe': answers/console (reverse-i-search)`answer': answers/console > answers/console
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.5 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.
scala>  (reverse-i-search)`':  (reverse-i-search)`i': val rng = new scala.util.Random (reverse-i-search)`im': implicitly[Int <%< Long] (reverse-i-search)`imp': implicitly[Int <%< Long] (reverse-i-search)`impo': import fpinscala.state._ (reverse-i-search)`impor': import fpinscala.state._ (reverse-i-search)`import': import fpinscala.state._ scala> import fpinscala.state._
import fpinscala.state._
scala> val rng = SimpleRNG(42)
scala> val rng = SimpleRNG(42)
<console>:10: error: not found: value SimpleRNG
val rng = SimpleRNG(42)
^
scala> val rng = SimpleRNG(42) (reverse-i-search)`':  (reverse-i-search)`S': a.asInstanceOf[Seq] (reverse-i-search)`Si': a.sequence(List(RNG.Simple(-10), RNG.Simple(-10))) (reverse-i-search)`Sim': a.sequence(List(RNG.Simple(-10), RNG.Simple(-10))) (reverse-i-search)`Simp': a.sequence(List(RNG.Simple(-10), RNG.Simple(-10))) (reverse-i-search)`Simpl': a.sequence(List(RNG.Simple(-10), RNG.Simple(-10))) (reverse-i-search)`Simple': a.sequence(List(RNG.Simple(-10), RNG.Simple(-10))) (reverse-i-search)`Simple': a.sequence(List(RNG.Simple(-10), List(RNG.Simple(-10)))) (reverse-i-search)`Simple': a.sequence(List(RNG.nonNegativeInt(RNG.Simple(-1))))  (reverse-i-search)`Simple': a.sequence(List(RNG.Simple(1))) scala> a.sequence(List(RNG.Simple(1)))val b = a.map2(a.nonNegativeInt, a.nonNegativeInt)((x, y) => x + y)b.apply(RNG.Simple(-100))1))1)toStringval b = a.map2(a.nonNegativeInt, a.nonNegativeInt)((x, y) => x + y)val val rng = SimpleRNG(42)(42)(42)(42)RSimple(42)NSimple(42)GSimple(42).Simple(42)
rng: fpinscala.state.RNG.Simple = Simple(42)
scala> val (n1, rng2) = rng.nextInt
n1: Int = 16159453
rng2: fpinscala.state.RNG = Simple(1059025964525)
scala> n1
res0: Int = 16159453
scala> rng2
res1: fpinscala.state.RNG = Simple(1059025964525)
scala> val (n2, rng3) = rng2.nextInt
n2: Int = -1281479697
rng3: fpinscala.state.RNG = Simple(197491923327988)
scala> rng2
res2: fpinscala.state.RNG = Simple(1059025964525)
scala> rng3
res3: fpinscala.state.RNG = Simple(197491923327988)
scala> rng
res4: fpinscala.state.RNG.Simple = Simple(42)
scala> rng
res5: fpinscala.state.RNG.Simple = Simple(42)
scala> rng
res6: fpinscala.state.RNG.Simple = Simple(42)
scala> rng
res7: fpinscala.state.RNG.Simple = Simple(42)
scala> rng.nextInt()1)0)
<console>:12: error: (Int, fpinscala.state.RNG) does not take parameters
rng.nextInt(10)
^
scala> rng.nextInt(10)
res9: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> rng.nextInt
res10: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> rng.nextInt
res11: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> rng.nextInt
res12: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> def randomPair(rng: RNG): (Int,Int) = {
| val (i1,_) = rng.nextInt
| val (i2,_) = rng.nextInt
| (i1,i2)
| }
randomPair: (rng: fpinscala.state.RNG)(Int, Int)
scala> randomrandomPair()r)n)g)
res13: (Int, Int) = (16159453,16159453)
scala> randomPair(rng)def randomPair(rng: RNG): ((Int,Int), RNG) = {
| val (i1,rng2) = rng.nextInt
| val (i2,rng3) = rng2.nextInt 1
<console>:3: error: ';' expected but integer literal found.
val (i2,rng3) = rng2.nextInt 1
^
scala> ((i1,i2), rng3) 2def randomPair(rng: RNG): ((Int,Int), RNG) = {
| val (i1,rng2) = rng.nextInt
| val (i2,rng3) = rng2.nextInt
| ((i1,i2), rng3)
| }
randomPair: (rng: fpinscala.state.RNG)((Int, Int), fpinscala.state.RNG)
scala> randomPair()r)n)g)
res14: ((Int, Int), fpinscala.state.RNG) = ((16159453,-1281479697),Simple(197491923327988))
scala> rng.nonRNG.nonvRNGaRNGlRNG RNGaRNG RNG=RNG RNG
a: fpinscala.state.RNG.type = fpinscala.state.RNG$@4900f729
scala> a.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> a.nonnonNegative
nonNegativeInt nonNegativeLessThan
scala> a.nonNegativeInonNegativeInt
def nonNegativeInt(rng: RNG): (Int, fpinscala.state.RNG)
scala> a.nonNegativeInt()r)n)g)
res15: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> a.nonNegativeInt(rng)rng
res16: fpinscala.state.RNG.Simple = Simple(42)
scala> rngrng = Simple()-)4)1)
<console>:11: error: reassignment to val
rng = Simple(-41)
^
scala> rng = Simple(-41)RSimple(-41)NSimple(-41)GSimple(-41).Simple(-41)
<console>:11: error: reassignment to val
rng = RNG.Simple(-41)
^
scala> rng = RNG.Simple(-41)vrng = RNG.Simple(-41)arng = RNG.Simple(-41)lrng = RNG.Simple(-41) rng = RNG.Simple(-41)
rng: fpinscala.state.RNG.Simple = Simple(-41)
scala> val rng = RNG.Simple(-41))2)
rng: fpinscala.state.RNG.Simple = Simple(-42)
scala> val rng = RNG.Simple(-42)1)rng = RNG.Simple(-41)Simple(-41)RNG.Simple(-41)Simple(-41)a.nonNegativeInt(rng)
res17: (Int, fpinscala.state.RNG) = (16159453,Simple(280415950746153))
scala> a.nonNegativeInt(rng)onNegativeInt(rng)nNegativeInt(rng)NegativeInt(rng)egativeInt(rng)gativeInt(rng)ativeInt(rng)tiveInt(rng)iveInt(rng)veInt(rng)eInt(rng)Int(rng)nInt(rng)eInt(rng)xInt(rng)tInt(rng)
<console>:13: error: value nextInt is not a member of object fpinscala.state.RNG
a.nextInt(rng)
^
scala> a.nextInt(rng).nextInt(rng)r.nextInt(rng)n.nextInt(rng)g.nextInt(rng)
res19: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> rng.nextInta.nextInt(rng)onNegativeInt(rng)
res20: (Int, fpinscala.state.RNG) = (16159453,Simple(280415950746153))
scala> Int.maxValue
<console>:11: error: value maxValue is not a member of object Int
Int.maxValue
^
scala> Int.maxValueInte
Integral InterruptedException
scala> InteInte
Integral InterruptedException
scala> InteetgIntegral
val Integral: math.Integral.type
scala> Integral.
ExtraImplicits Implicits asInstanceOf isInstanceOf toString
scala> Integral.Int
res22: Int.type = object scala.Int
scala> Integerral
res23: math.Integral.type = scala.math.Integral$@39f7378
scala> Integral.maval a = Int
a: Int.type = object scala.Int
scala> a.
MaxValue asInstanceOf int2double int2long toString
MinValue box int2float isInstanceOf unbox
scala> a.maMaxValue
res24: Int = 2147483647
scala> a.MaxValueMinValue
res25: Int = -2147483648
scala> 2147483648v2147483648a2147483648l2147483648 2147483648a2147483648 2147483648=2147483648 21474836482147483648214748364821474836482147483648i2147483648n2147483648t2147483648 2147483648=2147483648 2147483648
<console>:1: error: integer number too large
val int = 2147483648
^
scala> val int = 21474836487
int: Int = 2147483647
scala> val int = 21474836478-2147483648
int: Int = -2147483648
scala> val int = -21474836489
<console>:1: error: integer number too large
val int = -2147483649
^
scala> val int = -2147483649821474836478a.MinValueaxValueval a = IntIntegralval a = Inta.MaxValueval a = IntIntegral (reverse-i-search)`':  (reverse-i-search)`n': Int (reverse-i-search)`nr':  (reverse-i-search)`n': Int (reverse-i-search)`':  (reverse-i-search)`':  (reverse-i-search)`r': a.nonNegativeInt(rng) (reverse-i-search)`rn': a.nonNegativeInt(rng) (reverse-i-search)`rng': a.nonNegativeInt(rng) scala> a.nonNegativeInt(rng)onNegativeInt(rng)
MaxValue asInstanceOf int2double int2long toString
MinValue box int2float isInstanceOf unbox
scala> a.rng.
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.double
<console>:12: error: value double is not a member of fpinscala.state.RNG.Simple
rng.double
^
scala> rng.double
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.a.
MaxValue asInstanceOf int2double int2long toString
MinValue box int2float isInstanceOf unbox
scala> a.rnvala  (reverse-i-search)`':  (reverse-i-search)`v': val int = -2147483649 (reverse-i-search)`va': val int = -2147483649 (reverse-i-search)`val': val int = -2147483649 (reverse-i-search)`val ': val int = -2147483649 (reverse-i-search)`val a': val a = Int (reverse-i-search)`val a ': val a = Int (reverse-i-search)`val a ': val a = RNG scala> val a = RNG
a: fpinscala.state.RNG.type = fpinscala.state.RNG$@4900f729
scala> a.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> a.double
<console>:12: error: missing arguments for method double in object RNG;
follow this method with `_' if you want to treat it as a partially applied function
a.double
^
scala> a.doubledouble
double double3 doubleInt
scala> a.double
def double(rng: RNG): (Double, fpinscala.state.RNG)
scala> a.double()r)n)g)
res28: (Double, fpinscala.state.RNG) = (0.007524831686168909,Simple(280415950746153))
scala> Int.MaxValue.toDouble
res29: Double = 2.147483647E9
scala> Int.MaxValue.toDoubletoDouble
res30: Int = 2147483647
scala> Int.MaxValue.touDotoDouble.MaxValue
<console>:11: error: value MaxValue is not a member of Double
Int.MaxValue.toDouble.MaxValue
^
scala> Int.MaxValue.toDouble.MaxValueval double : Double = 0.1
double: Double = 0.1
scala> double.
% - >= toByte toFloat toShort unary_-
* / asInstanceOf toChar toInt toString
+ > isInstanceOf toDouble toLong unary_+
scala> double.val double: Double = 0.1rng.intDouble()r)n)g)ng.intDouble(rng)g.intDouble(rng).intDouble(rng)a
res32: fpinscala.state.RNG.type = fpinscala.state.RNG$@4900f729
scala> a.inint
int intDouble ints ints2
scala> a.intDouintDouble()r)n)g)
res33: ((Int, Double), fpinscala.state.RNG) = ((-16159454,0.6006770636886358),Simple(84537781268864))
scala> a.intDouble(rng)ntDouble(rng)tDouble(rng)Double(rng)ouble(rng)double(rng)I(rng)n(rng)t(rng)
res34: ((Double, Int), fpinscala.state.RNG) = ((0.6006770636886358,-16159454),Simple(84537781268864))
scala> a.double3()r)n)g)
res35: ((Double, Double, Double), fpinscala.state.RNG) = ((0.007524831686168909,0.6006770636886358,0.3249912904575467),Simple(45738457961355))
scala> a.ii
int intDouble ints ints2 isInstanceOf
scala> a.ints()ints
ints ints2
scala> a.ints
def ints(count: Int)(rng: RNG): (List[Int], fpinscala.state.RNG)
scala> a.ints()3)()n)r)))r)n)g)
res36: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.ints(3)(rng)
res37: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.ints(3)(rng)
res38: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.ints(3)(rng)
res39: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.ints(3)(rng)
res40: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.ints(3)(rng)
res41: (List[Int], fpinscala.state.RNG) = (List(-16159454, 1289944172, 697913482),Simple(45738457961355))
scala> a.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> a.int
res42: a.Rand[Int] = <function1>
scala> a.intint
int intDouble ints ints2
scala> a.int
val int: RNG => (Int, fpinscala.state.RNG)
scala> a.int
res43: a.Rand[Int] = <function1>
scala> a.int
res44: a.Rand[Int] = <function1>
scala>  (reverse-i-search)`':  (reverse-i-search)`a': a.int (reverse-i-search)`a.': a.int (reverse-i-search)`a.i': a.int (reverse-i-search)`a.in': a.int (reverse-i-search)`a.int': a.int scala> a.int.
andThen apply asInstanceOf compose isInstanceOf toString
scala> a.int.apply()1)0)
<console>:12: error: type mismatch;
found : Int(10)
required: fpinscala.state.RNG
a.int.apply(10)
^
scala> a.int.apply(10)))r)n)g)
res46: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int.apply(rng)
res47: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int.apply(rng)
res48: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int.apply(rng)
res49: a.Rand[Int] = <function1>
scala> a.intpa.intra.intia.intna.intta.intla.intna.int(a.int)
<function1>
scala> println(a.int)a.int()1)0)
<console>:12: error: type mismatch;
found : Int(10)
required: fpinscala.state.RNG
a.int(10)
^
scala> a.int(10)))r)n)g)
res52: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int(rng)
res53: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int(rng)2)
res54: (Int, fpinscala.state.RNG) = (-1281479697,Simple(197491923327988))
scala> a.int(rng2))3)
res55: (Int, fpinscala.state.RNG) = (-340305902,Simple(259172689157871))
scala> a.int(rng3)
res56: (Int, fpinscala.state.RNG) = (-340305902,Simple(259172689157871))
scala> a.int(rng3)
res57: (Int, fpinscala.state.RNG) = (-340305902,Simple(259172689157871))
scala> a.int(rng3)
res58: (Int, fpinscala.state.RNG) = (-340305902,Simple(259172689157871))
scala> ia.intint
int intDouble ints ints2
scala> a.int
val int: RNG => (Int, fpinscala.state.RNG)
scala> a.inta.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> a.unitunit
def unit[A](a: A): RNG => (A, fpinscala.state.RNG)
scala> a.unit()1)0)
res59: a.Rand[Int] = <function1>
scala> a.unit(10),) )))()r)n)g)
res60: (Int, fpinscala.state.RNG) = (10,Simple(-42))
scala> a.unit(10)(rng)
res61: (Int, fpinscala.state.RNG) = (10,Simple(-42))
scala> a.unit(10)(rng)a.unit(10)(rng)
res62: (Int, fpinscala.state.RNG) = (10,Simple(-42))
scala> a.unit(10)(rng)va.unit(10)(rng)aa.unit(10)(rng)la.unit(10)(rng)a.unit(10)(rng)a.unit(10)(rng)a.unit(10)(rng)va.unit(10)(rng)aa.unit(10)(rng)la.unit(10)(rng) a.unit(10)(rng)(a.unit(10)(rng))a.unit(10)(rng)o)a.unit(10)(rng)n)a.unit(10)(rng)e)a.unit(10)(rng),)a.unit(10)(rng) )a.unit(10)(rng)t)a.unit(10)(rng)w)a.unit(10)(rng)o)a.unit(10)(rng), two)a.unit(10)(rng), two)a.unit(10)(rng), two)a.unit(10)(rng)_, two)a.unit(10)(rng)wo)a.unit(10)(rng)o)a.unit(10)(rng))a.unit(10)(rng)r)a.unit(10)(rng)n)a.unit(10)(rng)g)a.unit(10)(rng)4)a.unit(10)(rng) a.unit(10)(rng)=a.unit(10)(rng) a.unit(10)(rng)
rng4: fpinscala.state.RNG = Simple(-42)
scala> rng4.nexnextInt
res63: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> rng4.nextInt.nextInt3.nextInt
res64: (Int, fpinscala.state.RNG) = (-340305902,Simple(259172689157871))
scala> rng3.nextInt
res65: fpinscala.state.RNG = Simple(197491923327988)
scala> rng3
res66: fpinscala.state.RNG.Simple = Simple(-42)
scala> rng4
res67: fpinscala.state.RNG = Simple(-42)
scala> rng4.u
asInstanceOf isInstanceOf nextInt toString
scala> rng4.rng.m
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.a.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> a.map()map
map map2
scala> a.map
def map[A, B](s: RNG => (A, fpinscala.state.RNG))(f: A => B): RNG => (B, fpinscala.state.RNG)
scala> a.map()r)n)g)()x) )=)>) )x) )+) )1)
<console>:13: error: type mismatch;
found : fpinscala.state.RNG.Simple
required: a.Rand[?]
(which expands to) fpinscala.state.RNG => (?, fpinscala.state.RNG)
a.map(rng)(x => x + 1)
^
scala> a.map(rng)(x => x + 1))(x => x + 1))(x => x + 1))(x => x + 1)a)(x => x + 1)
<console>:12: error: type mismatch;
found : fpinscala.state.RNG.type
required: a.Rand[?]
(which expands to) fpinscala.state.RNG => (?, fpinscala.state.RNG)
a.map(a)(x => x + 1)
^
scala> a.map(a)(x => x + 1).)(x => x + 1) )(x => x + 1)R )(x => x + 1) )(x => x + 1) )(x => x + 1) )(x => x + 1)r )(x => x + 1)n )(x => x + 1)g )(x => x + 1). )(x => x + 1)R )(x => x + 1)a )(x => x + 1)n )(x => x + 1)d )(x => x + 1))(x => x + 1)
<console>:13: error: value Rand is not a member of fpinscala.state.RNG.Simple
a.map(rng.Rand)(x => x + 1)
^
scala> a.map[]I]n]t]a.map(rng.Rand)(x => x + 1)a)(x => x + 1))(x => x + 1)3)(x => x + 1))(x => x + 1)I)(x => x + 1)n)(x => x + 1)t)(x => x + 1))(x => x + 1))(x => x + 1))(x => x + 1)i)(x => x + 1)n)(x => x + 1)t)(x => x + 1)
<console>:13: error: type mismatch;
found : Int
required: a.Rand[?]
(which expands to) fpinscala.state.RNG => (?, fpinscala.state.RNG)
a.map(int)(x => x + 1)
^
scala> a.map(int)(x => x + 1))(x => x + 1))(x => x + 1))(x => x + 1)a)(x => x + 1).)(x => x + 1)R)(x => x + 1)a)(x => x + 1)n)(x => x + 1)d)(x => x + 1)[)(x => x + 1)i)(x => x + 1))(x => x + 1)I)(x => x + 1)n)(x => x + 1)t)(x => x + 1)])(x => x + 1)val int = _.nextInt
<console>:10: error: missing parameter type for expanded function ((x$1) => x$1.nextInt)
val int = _.nextInt
^
scala> val int = _.nextInt: = _.nextInt = _.nextIntR = _.nextInta = _.nextIntn = _.nextIntd = _.nextInt
<console>:10: error: not found: type Rand
val int: Rand = _.nextInt
^
scala> val int: Rand = _.nextInt = _.nextInt = _.nextInt = _.nextInt = _.nextIntR = _.nextIntN = _.nextIntG = _.nextInt
<console>:10: error: missing parameter type for expanded function ((x$1) => x$1.nextInt)
val int: RNG = _.nextInt
^
scala> val int: RNG = _.nextInt = _.nextInt = _.nextInt = _.nextIntS = _.nextInti = _.nextIntm = _.nextIntp = _.nextIntl = _.nextInte = _.nextInt. = _.nextIntR = _.nextIntN = _.nextIntG = _.nextInt
<console>:10: error: not found: value Simple
val int: Simple.RNG = _.nextInt
^
scala> val int: Simple.RNG = _.nextInt
<console>:10: error: not found: value Simple
val int: Simple.RNG = _.nextInt
^
scala> val int: Rand[Int] = _.nextInt
<console>:10: error: not found: type Rand
val int: Rand[Int] = _.nextInt
^
scala> type Rand[+A] = RNG => (A, RNG)
defined type alias Rand
scala> val int: Rand[Int] = _.nextInt
int: Rand[Int] = <function1>
scala> val int: Rand[Int] = _.nextInttype Rand[+A] = RNG => (A, RNG)val int: Rand[Int] = _.nextIntSimple.RNG = _.nextIntRNG = _.nextIntand = _.nextInt = _.nextInta.map(int)(x => x + 1)
res72: a.Rand[Int] = <function1>
scala> a.map(int)(x => x + 1).RNG()r)n)g)
res73: (Int, fpinscala.state.RNG) = (-16159453,Simple(280415950746153))
scala> rng
res74: fpinscala.state.RNG.Simple = Simple(-42)
scala> rng.nextIntint()ng.int()g.int().int()a.int()r)n)g)
res75: (Int, fpinscala.state.RNG) = (-16159454,Simple(280415950746153))
scala> a.int(rng)rnga.map(int)(x => x + 1)(rng))(rng))(rng))(rng)/)(rng) )(rng)2)(rng))(rng))(rng))(rng)-)(rng) )(rng))(rng))(rng)+)(rng) )(rng)1)(rng)6)(rng)1)(rng)5)(rng)9)(rng)4)(rng)5)(rng)3)(rng)
res76: (Int, fpinscala.state.RNG) = (-1,Simple(280415950746153))
scala> def nonNegativeEven: Rand[Int] =
| map(nonNegativeInt)(i => i - i % 2)
<console>:12: error: not found: value map
map(nonNegativeInt)(i => i - i % 2)
^
<console>:12: error: not found: value nonNegativeInt
map(nonNegativeInt)(i => i - i % 2)
^
scala> map(nonNegativeInt)(i => i - i % 2)def nonNegativeEven: Rand[Int] =a.map(int)(x => x + 16159453)(rng)def nonNegativeEven: Rand[Int] =exit
<console>:11: error: not found: value exit
exit
^
scala> quit
<console>:11: error: not found: value quit
quit
^
scala> :q
[success] Total time: 4541 s, completed 2015/06/30 21:23:47
> answers/console
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.5 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.
scala>  (reverse-i-search)`':  (reverse-i-search)`i': quit (reverse-i-search)`im': val int: Simple.RNG = _.nextInt (reverse-i-search)`imp': val int: Simple.RNG = _.nextInt (reverse-i-search)`impo': import fpinscala.state._ (reverse-i-search)`impor': import fpinscala.state._ (reverse-i-search)`import': import fpinscala.state._ scala> import fpinscala.state._
import fpinscala.state._
scala> import fpinscala.state._:qimport fpinscala.state._rng vrng arng lrng  rng  = Simple.RNG(RSimple.NSimple.GSimple..Simple.()4)2)
rng: fpinscala.state.RNG.Simple = Simple(42)
scala> rng.
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.val rand = RNG
rand: fpinscala.state.RNG.type = fpinscala.state.RNG$@6679d20e
scala> rand.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> rand.rng._rand.__
_double _ints _map _map2
scala> rand._dou_double
val _double: RNG => (Double, fpinscala.state.RNG)
scala> rand._double()r)n)g)
res0: (Double, fpinscala.state.RNG) = (0.007524831686168909,Simple(1059025964525))
scala> rand._double(rng)(rng)(rng)(rng)(rng)(rng)(rng)(rng)d(rng)o(rng)u(rng)b(rng)l(rng)e(rng)
res1: (Double, fpinscala.state.RNG) = (0.007524831686168909,Simple(1059025964525))
scala> rand.double(rng)int(()r)n)t))g)
res2: (Int, fpinscala.state.RNG) = (16159453,Simple(1059025964525))
scala> rand.int(rng)_int(rng)
<console>:13: error: value _int is not a member of object fpinscala.state.RNG
rand._int(rng)
^
scala> :q
[success] Total time: 222 s, completed 2015/06/30 21:27:31
> compile
[info] Updating {file:/home/shigemk2/projects/github.com/shigemk2/fpinscala/}exercises...
[info] Updating {file:/home/shigemk2/projects/github.com/shigemk2/fpinscala/}fpinscala...
[info] Updating {file:/home/shigemk2/projects/github.com/shigemk2/fpinscala/}chapter-code...
[info] Resolving org.scala-lang#scala-library;2.11.5 ...
M[info] Resolving org.scala-lang#scala-compiler;2.11.5 ...
M[info] Resolving org.scala-lang#scala-reflect;2.11.5 ...
M[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.3 ...
M[info] Resolving org.scala-lang.modules#scala-parser-combinators_2.11;1.0.3 ...
M[info] Resolving jline#jline;2.12 ...
[info] Done updating.
[info] Resolving org.scala-lang#scala-library;2.11.5 ...
M[info] Resolving org.scala-lang#scala-compiler;2.11.5 ...
M[info] Resolving org.scala-lang#scala-reflect;2.11.5 ...
M[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.3 ...
M[info] Resolving org.scala-lang.modules#scala-parser-combinators_2.11;1.0.3 ...
M[info] Resolving jline#jline;2.12 ...
[info] Done updating.
[info] Resolving org.scala-lang#scala-library;2.11.5 ...
M[info] Resolving org.scala-lang#scala-compiler;2.11.5 ...
M[info] Resolving org.scala-lang#scala-reflect;2.11.5 ...
M[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.3 ...
M[info] Resolving org.scala-lang.modules#scala-parser-combinators_2.11;1.0.3 ...
M[info] Resolving jline#jline;2.12 ...
[info] Done updating.
[info] Compiling 22 Scala sources to /home/shigemk2/projects/github.com/shigemk2/fpinscala/exercises/target/scala-2.11/classes...
[warn] there were four deprecation warnings; re-run with -deprecation for details
[warn] there were 63 feature warnings; re-run with -feature for details
[warn] two warnings found
[success] Total time: 33 s, completed 2015/06/30 21:28:07
>  (reverse-i-search)`':  (reverse-i-search)`a': answers/console (reverse-i-search)`an': answers/console (reverse-i-search)`ans': answers/console (reverse-i-search)`answ': answers/console (reverse-i-search)`answe': answers/console (reverse-i-search)`answer': answers/console > answers/console
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.5 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.
scala>  (reverse-i-search)`':  (reverse-i-search)`i': rand._int(rng) (reverse-i-search)`im': val rng = RNG.Simple(42) (reverse-i-search)`imp': val rng = RNG.Simple(42) (reverse-i-search)`impo': import fpinscala.state._ (reverse-i-search)`impor': import fpinscala.state._ scala> import fpinscala.state._
import fpinscala.state._
scala>  (reverse-i-search)`':  (reverse-i-search)`R': val rand = RNG (reverse-i-search)`RN': val rand = RNG (reverse-i-search)`RNG': val rand = RNG scala> val rand = RNG
rand: fpinscala.state.RNG.type = fpinscala.state.RNG$@745430f3
scala>  (reverse-i-search)`':  (reverse-i-search)`r': val rand = RNG (reverse-i-search)`rn': rand._int(rng) (reverse-i-search)`rng': rand._int(rng) (reverse-i-search)`rng': rand.int(rng) (reverse-i-search)`rng': rand.double(rng) (reverse-i-search)`rng': rand._double(rng) (reverse-i-search)`rng': val rng = RNG.Simple(42) scala> val rng = RNG.Simple(42)
rng: fpinscala.state.RNG.Simple = Simple(42)
scala> rng.dou
asInstanceOf isInstanceOf productElement seed
canEqual nextInt productIterator toString
copy productArity productPrefix
scala> rng.?_rnad.and.doudouble
double double3 doubleInt
scala> rand.double
<console>:12: error: missing arguments for method double in object RNG;
follow this method with `_' if you want to treat it as a partially applied function
rand.double
^
scala> rand.double()r)n)g)
res1: (Double, fpinscala.state.RNG) = (0.007524831686168909,Simple(1059025964525))
scala> rand.double(rng)nexval rng = RNG.Simple(42)rand.doublerng.nonrand.nonnonNegative
nonNegativeInt nonNegativeLessThan
scala> rand.nonNegativeNeEven()3)
<console>:12: error: value nonNegativeEven is not a member of object fpinscala.state.RNG
rand.nonNegativeEven
^
scala> rand.
Rand boolean int map2 toString
_double both intDouble nonNegativeInt unit
_ints double ints nonNegativeLessThan
_map double3 ints2 randDoubleInt
_map2 doubleInt isInstanceOf randIntDouble
asInstanceOf flatMap map sequence
scala> rand.nonnonNegative
nonNegativeInt nonNegativeLessThan
scala> rand.nonNegative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment