| title |
|---|
Functional Programming |
Conception, evolution, and application of functional programming languages
The algebra of types
| val hconfig = config("hconfig").extend(Compile) | |
| lazy val hconsole = taskKey[Unit]("hconsole") | |
| lazy val destroySchema = taskKey[Unit]("destroySchema") | |
| hconsole := (console in hconfig).value | |
| val slickperf = project.in(file(".")). | |
| configs(hconfig). | |
| settings(inConfig(hconfig)(Defaults.configTasks) : _*) |
| /* To be used with the online version of Purescript by Example https://leanpub.com/purescript/read */ | |
| #read-online { color:black } | |
| #read-online .read { width:auto } | |
| .sidebar { | |
| position: absolute; | |
| margin-left: 450px; /* this is to make sure the book add stays visible, probably there is more reliable way of doing this */ | |
| } |
| {- | |
| From: https://gist.github.com/pedrofurla/12516a6998ca39520b14 | |
| Re-interpretation of the problem: | |
| - An imaginary room of size N x M, | |
| - Contains a robot that can move one unit (of the above scale) at a time. | |
| - Attempting to cross the boundaries of the room has no effect. | |
| - Certain positions contains patchs of dirty. If the robot gets to that position it is cleansed. | |
| Program organization: |
| def title[A <: { def name:String }](a:A):A = { print(a.name); a} | |
| suppose we have Company(name:String, address:String), Person(name:String, age:Int) | |
| title(person).age | |
| title(company).address | |
| title(person).address // error |
| addCommandAlias("git", "; sh git") | |
| commands ++= Seq( | |
| Command.args("sh", "<shell command>") { (state, args) => | |
| // using script here maintains ansi colors, see http://stackoverflow.com/a/13587964/467390 | |
| val ret = ("script -q /dev/null " ++ args.mkString(" ")) !; | |
| state | |
| } | |
| ) |
| function *gen(x) { | |
| var i = yield(x + 1); | |
| console.log(i, typeof i); | |
| var y = 2 * i; | |
| var z = yield (y/3); | |
| return x + y +z | |
| } | |
| var g = gen(5) |
| object Tmp { | |
| "zzz" ++ "kkk" // Fails with -Yno-predef | |
| // after typer the above is scala.this.Predef.augmentString("zzz").++[Char, String](scala.this.Predef.augmentString("kkk"))(scala.this.Predef.StringCanBuildFrom); | |
| "aaa"+new Object() // Doesn't fail ever! | |
| // after typer the above is "aaa".+(new java.this.lang.Object()); | |
| // Why didn't `+` desugar to something else? | |
| new Object() + "aaa" // Fails with -Yno-predef |
| open /Applications/Google\ Chrome.app --args --allow-file-access-from-files --unlimited-quota-for-files |
| sealed trait List[+A] { | |
| override def toString = { | |
| def toScalaList(t: List[A]): scala.List[A] = t match { | |
| case Empty => Nil | |
| case Cons(h, t) => h :: toScalaList(t) | |
| } | |
| toScalaList(this).toString | |
| } | |
| } | |
| final case object Empty extends List[Nothing] |