Skip to content

Instantly share code, notes, and snippets.

Avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
View gist:d407e44bca0b2fb682d5
### 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:
View gist:2da1446be99dfa94f04f
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
quasiquote patternmatch for comprehension
View 2.10.4.scala
> ++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]
View playjson.scala
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 Apr 27, 2018
Ackermann function
View gist:6258410
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 Oct 10, 2020
Table of unicode operators in scalaz 6.0.x
View gist:6089236
View so.scala
> 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 Dec 18, 2015
Parallelizing lazy Streams.
View gist:5766269
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)
View HindleyMilner.scala
/*
* 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
*
@folone
folone / IoOverflow.scala
Last active Dec 16, 2015
IO monad stack overflow
View IoOverflow.scala
> effect/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._, Scalaz._, effect._
You can’t perform that action at this time.