Skip to content

Instantly share code, notes, and snippets.

View aoiroaoino's full-sized avatar
🏠
Working from home

Naoki Aoyama aoiroaoino

🏠
Working from home
View GitHub Profile
> run
[info] Updating {file:/Users/aoino/work/native-hello/}native-hello...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/aoino/work/native-hello/target/scala-2.11/classes...
[info] running
[info] /usr/bin/clang
[info] -I/usr/local/include
[info] -c
[info] /Users/aoino/work/native-hello/target/scala-2.11/nativelib/dyndispatch.c
> run
[info] Updating {file:/Users/aoino/work/native-hello/}native-hello...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/aoino/work/native-hello/target/scala-2.11/classes...
[info] running
[info] /usr/bin/clang
[info] -I/usr/local/include
[info] -c
[info] /Users/aoino/work/native-hello/target/scala-2.11/nativelib/dyndispatch.c

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

Miles Sabin 氏は、最近悪名高き SI-2712 を修正する pull req を出した。第一に、これは注目すべきものであり、もし merge されたら全ての人々の生活が非常に楽になるだろう。このバグは、何か間違っているか、変な使い方によって compiler が壊れてしまったかのどちらかと仮定され、多くの人々がしばしば意図せず遭遇した。これは"特に" scalaz または cats ユーザーの間で一般的だ。

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

しかし、私が書きたいのはそれではありません。私が書きたいのは Miles 氏の修正の正確な意味論で、(wip

scalaVersion := "2.11.8"
enablePlugins(PlayScala)
@aoiroaoino
aoiroaoino / build.sbt
Last active June 10, 2016 08:20
Lens の実用例
import sbt._
name := "monocle-template"
scalaVersion := "2.11.8"
licenses := Seq("MIT License" -> url("http://opensource.org/licenses/mit"))
scalacOptions ++= Seq(
"-deprecation",
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_65).
Type in expressions for evaluation. Or try :help.
scala> object Foo { case class Bar private(a: Long); Bar(100) }
defined object Foo
scala> object Foo { case class Bar private(a: Long); new Bar(100) }
<console>:11: error: constructor Bar in class Bar cannot be accessed in object Foo
object Foo { case class Bar private(a: Long); new Bar(100) }
^
@aoiroaoino
aoiroaoino / error.log
Created March 12, 2016 14:33
occurrd error when use %%%
/Users/aoino/work/git/Monocle/build.sbt:33: error: `value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting.
lazy val scalaz = "org.scalaz" %%% "scalaz-core" % "7.2.1"
^
sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import akka.actor.ActorSystem
import akka.actor.ActorSystem
scala> import akka.stream.ActorMaterializer
import akka.stream.ActorMaterializer
@aoiroaoino
aoiroaoino / Either3OpticsSample.scala
Created September 3, 2015 11:37
Either3Optics sample code.
trait Either3Optics {
final def pLeft3[A, B, C, D]: PPrism[Either3[A, B, C], Either3[D, B, C], A, D] =
PPrism[Either3[A, B, C], Either3[D, B, C], A, D] {
case Left3(a) => \/-(a)
case Middle3(b) => -\/(Middle3(b))
case Right3(c) => -\/(Right3(c))
}(Left3.apply)
final def left3[A, B, C]: Prism[Either3[A, B, C], A] =
object EDCBA {
case class A(value: Int)
case class B(value: Option[A])
case class C(value: B)
case class D(value: Option[C])
case class E(value: D)
val edcba: Option[E] = Some(E(D(Some(C(B(Some(A(1))))))))