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
@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 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 / 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",
scalaVersion := "2.11.8"
enablePlugins(PlayScala)

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

> 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
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))
@aoiroaoino
aoiroaoino / build.sbt
Last active March 28, 2018 12:40
VL-Lens in Scala
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",
@aoiroaoino
aoiroaoino / a.md
Last active September 16, 2019 06:28
Scala秋祭り2019 発表資料内に登場するソースコードの元