This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Functor[A, F[_]] { self => | |
def fmap[B](f: A => B): F[B] | |
} | |
trait ~>[-F[_], +G[_]]{ | |
def apply[A](fa: F[A]): G[A] | |
} | |
object Functor { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[syntax trees at end of jvm]] // Param.scala | |
package <empty> { | |
final class Param extends Object { | |
<paramaccessor> private[this] val i: Int = _; | |
<stable> <accessor> <paramaccessor> def i(): Int = Param.this.i; | |
override <synthetic> def hashCode(): Int = Param.hashCode$extension(Param.this.i()); | |
override <synthetic> def equals(x$1: Object): Boolean = Param.equals$extension(Param.this.i(), x$1); | |
def <init>(i: Int): Param = { | |
Param.this.i = i; | |
Param.super.<init>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Prob44_2 { | |
def pentagonal(n: Int) = n*(3*n - 1)/2 | |
private[this] val pentagonals = Iterator.from(0).map(pentagonal).takeWhile(_ < (Int.MaxValue >> 2)).toArray | |
def isPenta(n: Int) = { | |
val dbl = (1.0 + math.sqrt(1 + 24*n))/6.0 | |
val int = dbl.toInt | |
pentagonal(int) == n || pentagonal(int + 1) == n | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> class Bippy(xs: List[Int]) extends improving.TypesafeProxy(xs) { def isEmpty = true } | |
defined class Bippy | |
scala> val bippy = new Bippy(1 to 10 toList) | |
bippy: Bippy = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | |
scala> bippy.slice(3, 7) | |
[proxy] $line4.$read.$iw.$iw.bippy.slice(3, 7) | |
res1: List[Int] = List(4, 5, 6, 7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.higherKinds | |
import scala.language.implicitConversions | |
trait Forall[M[_]] { | |
def apply[A]: M[A] | |
} | |
trait Maybe[A] extends Forall[({ type F[R] = (A => R, => R) => R })#F] | |
object Maybe { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The z in scalaz means this: it was early 2008 and I was working for a Java consultancy and so of course, I used the most appropriate tool for the job: scala. But it had *terrible* libraries, so I offered to fix those while also meeting my other objectives. Turns out that the Scala guys were extremely hostile to even half-decent libraries (and still are to this day). I still struggle to wrap my head around this sometimes. | |
Anyway, so I thought, well fuck it, I will just keep them to myself for now. My (awesome) employer had already agreed that we'd probably open-source such a thing, but I was concerned most about my primary goal. So then it came time to "name" this library. I had named it "scalax" simply so that I did not have the inclination to think of a proper name. Then I found out that such a library was being developed and with my internal name! Whatever, I thought. | |
So I looked at this scalax library, hoping that I could just abandon my efforts and jump on board with everyone else -- they too had figure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import Build.data | |
object build extends Build { | |
lazy val runAll = TaskKey[Unit]("run-all") | |
lazy val standardSettings = Seq( | |
runAllIn(Compile) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package s | |
object Test { | |
// Observe that x.companion is statically typed such that foo is callable | |
def f1() = { | |
val x = new Foo | |
println(x) // Foo instance | |
println(x.companion) // Foo companion | |
println(x.companion.foo) // I'm foo! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.reflect.runtime.universe._ | |
import scala.reflect._ | |
object App{ | |
def main(args : Array[String]){ | |
val m = toMap(User("Kudo",2,false)) | |
println(m) | |
//Map(admin_? -> false, gender -> 2, name -> Kudo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, Rank2Types, TypeOperators #-} | |
newtype Id a = | |
Id a | |
data a :\/ b = | |
Left a | |
| Right b | |
data a :/\ b = |