Scalaの記事です。Haskellはあまり書けません。
Iterateeの複雑さから開放されたいのでPipe系ライブラリ使いましょうという記事です。
Iterateeとの比較や簡単な使い方についてつらつらと書いていきます。
package disample | |
case class DiSampleConfig(foo: Int, bar: String) | |
object DiSampleConfig { | |
implicit val configs: Configs[DiSampleConfig] = Configs { c => | |
DiSampleConfig( | |
foo = c.get[Int]("foo"), | |
bar = c.get[String]("bar") | |
) | |
} |
(ns typelogic.lisp | |
(:refer-clojure :exclude [==]) | |
(:require [clojure.core.logic :refer :all] | |
[clojure.core.logic.dcg :refer :all])) | |
(defna expr [g x t] | |
([[[x t] . _] x t]) | |
([[_ . g'] x t] (expr g' x t)) | |
([_ ['fn [a] b] [::-> p q]] | |
(fresh [g'] |
sealed trait Status | |
sealed trait HasID extends Status | |
sealed trait NoID extends Status | |
case class User[S <: Status]( | |
firstName: String, | |
lastName: String, | |
age: Int, | |
createdAt: java.util.Date, | |
private val _id: Int = 0 |
~/210x $ scala -Xshow-phases | |
phase name id description | |
---------- -- ----------- | |
parser 1 parse source into ASTs, perform simple desugaring | |
macroparadise 2 let our powers combine | |
namer 3 resolve names, attach symbols to named trees in paradise | |
packageobjects 4 load package objects in paradise | |
typer 5 the meat and potatoes: type the trees in paradise | |
... |
def point(a: BufferedImage, b: BufferedImage) = | |
for { | |
points <- (for { | |
ax <- 0.to(a.getWidth - b.getWidth).view | |
ay <- 0.to(a.getHeight - b.getHeight).view | |
} yield { | |
for { | |
bx <- 0.until(b.getWidth).view | |
by <- 0.until(b.getHeight).view | |
} yield (ax, ay) -> (bx, by) |
Akkaのネットワーキングでは、2者間の通信を最小単位としてプロトコルを組む。
A <-- Protocol --> B
2者間のプロトコルの実装はPipelineと呼ばれる。 PipelineはAからのメッセージをBに通じるように翻訳し、一方でBからのメッセージをAに通じるように翻訳するという働きをする。
import sbt._ | |
import sbt.Keys._ | |
object ScalaoauthasyncBuild extends Build { | |
lazy val scalaoauthasync = Project( | |
id = "scala-oauth-async", | |
base = file("."), | |
settings = Project.defaultSettings ++ Seq( | |
name := "scala-oauth-async", |
(defn points [^BufferedImage image ^BufferedImage screen] | |
(let [width (.getWidth image) | |
height (.getHeight image) | |
xrange (range width) | |
yrange (range height)] | |
(for [points | |
(for [sx (range (- (.getWidth screen) width)) | |
sy (range (- (.getHeight screen) height))] | |
(for [tx xrange | |
ty yrange] |
package example | |
import scalikejdbc._, SQLInterpolation._, config._, async._ | |
import org.fluentd.logger.scala._ | |
import org.scalatest._, matchers._ | |
import scala.concurrent._, duration.DurationInt, ExecutionContext.Implicits.global | |
class SampleSpec extends FlatSpec with ShouldMatchers { | |
case class Name(id: Long, kanji: String, kana: String) |