Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
### Keybase proof
I hereby claim:
* I am folone on github.
* I am folone (https://keybase.io/folone) on keybase.
* I have a public key whose fingerprint is 5B9B 8355 136D CA8B F2DD F8CE EC51 AF2A 9ABC 8D1B
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am folone on github.
* I am folone (https://keybase.io/folone) on keybase.
* I have a public key whose fingerprint is 3A57 D1D4 67F6 0189 3CB7 03D8 FA5C 9955 37B3 71EF
To claim this, I am signing this object:
scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
scala> def mkAssoc[K, V0](k: K, v: V0): Assoc[k.type] { type V = V0 } =
| new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [K, V0](k: K, v: V0)Assoc[k.type]{type V = V0}
scala> def lookup[K](k: K)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value
lookup: [K](k: K)(implicit assoc: Assoc[k.type])assoc.V
@folone
folone / 2.10.4.scala
Created May 23, 2014 12:36
quasiquote patternmatch for comprehension
> ++2.10.4
[info] Setting version to 2.10.4
[info] Set current project to wartremover (in build file:/Users/georgii/workspace/wartremover/)
> console
[info] Updating {file:/Users/georgii/workspace/wartremover/}wartremover...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 24 Scala sources to /Users/georgii/workspace/wartremover/target/scala-2.10/classes...
[info] Starting scala interpreter...
[info]
scala> import play.api.libs.json._
import play.api.libs.json._
scala> case class Test[A: Writes](a: A)
defined class Test
scala> implicit def testWrites[A: Writes] = Json.writes[Test[A]]
<console>:12: error: No apply function found matching unapply parameters
implicit def testWrites[A: Writes] = Json.writes[Test[A]]
^
@folone
folone / gist:6258410
Last active April 27, 2018 14:09
Ackermann function
def ackermann(m: Int, n: Int): Int = {
(m, n) match {
case (0, _) ⇒ n + 1
case (m, 0) if m > 0 ⇒ ackermann(m - 1, 1)
case (m, n) if m > 0 && n > 0 ⇒ ackermann(m - 1, ackermann(m, n - 1))
}
}
import scalaz._, Scalaz._, Free.{suspend ⇒ _, _}, Trampoline._
def ackermannTramp(m: Int, n: Int): Trampoline[Int] = {
@folone
folone / gist:6089236
Last active October 10, 2020 18:26
Table of unicode operators in scalaz 6.0.x
@folone
folone / so.scala
Last active December 19, 2015 23:59
> shapeless-examples/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[warn] Binary version (2.10) for dependency org.scala-lang#scala-library;2.10.2
[warn] in com.chuusai#shapeless_2.10.2;2.0.0-SNAPSHOT differs from Scala binary version in project (2.10.2).
[warn] Binary version (2.10) for dependency org.scala-lang#scala-compiler;2.10.2
[warn] in com.chuusai#shapeless_2.10.2;2.0.0-SNAPSHOT differs from Scala binary version in project (2.10.2).
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_40).
Type in expressions to have them evaluated.
@folone
folone / gist:5766269
Last active December 18, 2015 10:09
Parallelizing lazy Streams.
final val BATCH_SIZE = (Runtime.getRuntime.freeMemory / 1024).toInt // kb per object should be enough, right?
def doStuff(m: MyType): Stream[MyType] = ??? // Costly operation
val s: Stream[MyType] = ???
s.grouped(BATCH_SIZE).toStream.flatMap(_.par flatMap doStuff)
/*
* http://dysphoria.net/code/hindley-milner/HindleyMilner.scala
* Andrew Forrest
*
* Implementation of basic polymorphic type-checking for a simple language.
* Based heavily on Nikita Borisov’s Perl implementation at
* http://web.archive.org/web/20050420002559/www.cs.berkeley.edu/~nikitab/courses/cs263/hm.html
* which in turn is based on the paper by Luca Cardelli at
* http://lucacardelli.name/Papers/BasicTypechecking.pdf
*