resolutely experimental project into library which, while s+ll tes+ng the limits of what's possible in Scala, is being used widely in produc+on systems wherever there are ari+es to be abstracted over and boilerplate to be scrapped.” hIps:/ /github.com/milessabin/shapeless
the result (root), as the nearest value to 0, of a func+on by repeatedly supplying varying parameter values to the func+on. Parameters values range 0.0 -‐> 1.0 Parameter arity 1 ~> 10 hIp:/ /en.wikipedia.org/wiki/Solver
Double, c : Double) : Double = (a - 0.2) + (b - 0.5) + (c - 0.7) The underlying Java port of solver uses Arrays to express the root hints, the func+on parameters and the parameters that get nearest to the func+ons root. def solveInternal( hint : Array[Double], func : (Array[Double]) => Double) : Array[Double]
Func+on was arity 4. Need to ‘lock together’ the arity of the hint, func+on parameters, and resul+ng array. Catch all of these errors at compile +me. Use the compiler to eliminate all of the ‘arity mismatch’ test cases.
into the type system and use these to constrain the size of the Arrays. Shapeless Has … • ‘Nat’ -‐ natural number type encodings • ‘Sized’ -‐ compile +me sized collec+ons
: Sized[IndexedSeq[Double], nat._3]) : Double = { val a = params at Nat(0) import nat._ val b = params at _1 val c = params(_2) (a - 0.2) + (b - 0.5) + (c - 0.7) } val s = solve( hints, toBeSolved )
Rou+ng and Parboiled 2. In parsing the DSLs parboiled2 pushes values onto an HList stack and pops them as required, as parameter to func+ons for example. hIps:/ /github.com/sirthias/parboiled2
purely func+on encoding/decoding of binary data. Uses HLists to do automa+c case class binding. case class Point(x: Int, y: Int, z: Int) val pointCodec = (int8 :: int8 :: int8).as[Point]) hIps:/ /github.com/scodec/scodec