Skip to content

Instantly share code, notes, and snippets.

@adriaanm
adriaanm / nightly.sbt
Created December 11, 2016 19:13
How to use the latest Scala nightly build from your sbt build by @SethTisue
// originally by @SethTisue, see http://stackoverflow.com/questions/40622878/how-do-i-tell-sbt-to-use-a-nightly-build-of-scala-2-11-or-2-12/40622879#40622879
resolvers += "nightlies" at "https://scala-ci.typesafe.com/artifactory/scala-release-temp/"
scalaVersion := {
val propsUrl = new URL("https://scala-ci.typesafe.com/job/scala-2.12.x-integrate-bootstrap/lastSuccessfulBuild/artifact/jenkins.properties/*view*/")
val props = new java.util.Properties
props.load(propsUrl.openStream)
props.getProperty("version")
}
scalaBinaryVersion := "2.12"
@mandubian
mandubian / ASample.scala
Last active January 20, 2017 17:30
Encoding Category Theory Laws (à-la-scalaz/cats) using kind-polymorphic List and compare/manipulate laws of structure
/**
* In classic Scala implementation of hierarchies of Category theory laws (scalaz/cats), the dependency between
* different laws is encoded using inheritance (https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Monad.scala#L14)
*
* This approach creates well-known issues: for example, a Monad is able to _derive_ an Applicative.
* So sometimes, you don't have the Applicative you want but the one derived from the Monad or it doesn't
* compile because you have 2 Applicatives in your implicit scope.
*
* Alois Cochard has proposed a new model to represent that in (scato project)[https://github.com/aloiscochard/scato] or
* (scalaz/8.0.x)[https://github.com/scalaz/scalaz/blob/series/8.0.x/base/src/main/scala/typeclass/Monad.scala] branch.
@mandubian
mandubian / kind_polymorphic.scala
Last active November 28, 2016 20:33
PoC for Kind Polymorphism in Scala
// That compiles for real in a patched version of Scala just introducing the KindPolymorphic syntax
object Test {
// Basic Kind polymorphism sample
trait Foo[T <: KindPolymorphic] { type Out ; def id(t: Out): Out = t }
object Foo {
implicit def foo0[T] = new Foo[T] { type Out = T }
implicit def foo1[T[_]] = new Foo[T] { type Out = T[Any] }
implicit def foo2[T[_, _]] = new Foo[T] { type Out = T[Any, Any] }
}
trait Semigroup[A] {}
trait Monoid[A] extends Semigroup[A] {}
trait Functor[F[_]] {}
trait Applicative[F[_]] extends Functor[F] {}
trait Foo[A] { override def toString: String = "Foo"}
trait Foo2[A] extends Foo[A] { override def toString: String = "Foo2"}
trait Foo3[A] extends Foo2[A] {override def toString: String = "Foo3"}
class TC[A](val x: String)
object TC {
def getX[A: TC](a: A): String = implicitly[TC[A]].x
implicit def anyTC[A]: TC[A] = new TC[A]("*")
implicit val stringTC: TC[String] = new TC[String]("String")
}
object Example {
@jbgi
jbgi / AdtEncodingsBench.scala
Last active September 23, 2016 18:57
Pattern matching is overrated! All we need is a catamorphism!
package scalaz
import org.openjdk.jmh.annotations._
@Fork(1)
@BenchmarkMode(Array(Mode.Throughput))
class AdtEncodingsBench {
import AdtEncodingsBench._

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@marchof
marchof / Console.txt
Created August 12, 2016 11:53
Exception in Cyclic interface causes JVM Crash
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006fe21b55, pid=14180, tid=0x00000000000038dc
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V [jvm.dll+0x201b55]
#
@reactormonk
reactormonk / Symbols.md
Last active November 19, 2021 14:06
Scalaz Symbol Guide
Symbol Explanation Hint
\/ Right-leaning Either Split ways, go one way or the other
-\/ Left value of \/ - is on the left side
\/- Right value of \/ - is on the right side
>>= flatMap shove result into
>> flatMap(_ => ..) shove into, but ignore the result
|@| Applicatives into Tuple Scream operator
|+| Append via Monoid + was taken
`> ` fa.map(_ =&gt; b)
@tonymorris
tonymorris / 20160529-Scalaz.md
Last active June 5, 2016 21:08
Scalaz hangout 20160529
  • How to denote identity structure
    • Have both
    • case class Identity[A](a: A)
    • type Id[X] = X
      • To use in certain circumstances (but not in transformers)
  • use kenji's scalaprops for testing?
    • strong yes -- Tony
  • starting point: Lens + basic data structures & type-classes [Identity, Const, Functor, Applicative, Traverse, Profunctor, Strong, Choice]
  • Task or IO or ?
  • IO not in base (too experimental -- into base once decided?)