Skip to content

Instantly share code, notes, and snippets.

@aoiroaoino
aoiroaoino / tf_example.scala
Created Oct 27, 2019
scala関西Summit 2019 アンカンファレンス
View tf_example.scala
package tf
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try
// === Predef
trait Monad[F[_]] {
def pure[A](f: A): F[A]
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
View unload_class.scala
import scala.language.existentials
import java.net._
var loader = new URLClassLoader(Array(new URL("file:///tmp/example/")))
val wrCat = new java.lang.ref.WeakReference(loader.loadClass("example.Cat"))
println("=== class cat: " + wrCat.get)
println("~~~ remove loader ~~~")
loader = null
@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)
You can’t perform that action at this time.