| title |
|---|
Functional Programming |
Conception, evolution, and application of functional programming languages
The algebra of types
| open /Applications/Google\ Chrome.app --args --allow-file-access-from-files --unlimited-quota-for-files |
| 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 |
| 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) |
| 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 | |
| } | |
| ) |
| 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 |
| {- | |
| 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: |
| /* 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 */ | |
| } |
| 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) : _*) |
| val startH2Task = TaskKey[Unit]("start-h2", "Starts H2 DB") | |
| val stopH2Task = TaskKey[Unit]("stop-h2", "Stops H2 DB") | |
| val h2tasks:Seq[Setting[_]] = Seq(startH2Task := { | |
| org.h2.tools.Server.createTcpServer().start(); | |
| org.h2.tools.Server.createWebServer().start // this starts the "web tool" | |
| }, stopH2Task :={ | |
| org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9092","",true,true); | |
| } ) |