Skip to content

Instantly share code, notes, and snippets.

Naoki Aoyama aoiroaoino

Block or report user

Report or block aoiroaoino

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aoiroaoino
aoiroaoino / a.md
Last active Sep 16, 2019
Scala秋祭り2019 発表資料内に登場するソースコードの元
View a.md
@aoiroaoino
aoiroaoino / build.sbt
Last active Mar 28, 2018
VL-Lens in Scala
View build.sbt
import Dependencies._
lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.11.11",
version := "0.1.0-SNAPSHOT"
)),
name := "vr-lens-demo",
View foo.scala
import monocle.Lens
case class Foo(bar: Option[String])
val _bar = Lens[Foo, Option[String]](_.bar)(s => foo => foo.copy(bar = s))
def いい感じにする(foo: Foo)(s: String): Foo = _bar.modify(bar => bar orElse Some(s))(foo)
// scala> いい感じにする(Foo(Some("bbb")))("aaa")
// res0: Foo = Foo(Some(bbb))
View gist:cac46bcd5d68a87950dd07945bfb7e05
> 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
View gist:e4c4abb87864c41b1a5da4ffcadbd1a7
> 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
View we-are-the-cure.md

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

View build.sbt
scalaVersion := "2.11.8"
enablePlugins(PlayScala)
@aoiroaoino
aoiroaoino / build.sbt
Last active Jun 10, 2016
Lens の実用例
View build.sbt
import sbt._
name := "monocle-template"
scalaVersion := "2.11.8"
licenses := Seq("MIT License" -> url("http://opensource.org/licenses/mit"))
scalacOptions ++= Seq(
"-deprecation",
View private_constructor
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 Mar 12, 2016
occurrd error when use %%%
View error.log
/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
You can’t perform that action at this time.