Scalaz | |||
Symbol | Code | Ascii | Example |
---|---|---|---|
η | 951 | pure | 1.η[List] |
μ | 03BC | join | List(List(1,2,3), nil, List(5,6,7)) μ |
∅ | 2205 | zero | ∅[Int] |
<∅> | empty | <∅>[Option, Int] |
|
∙ | 2219 | contramap | ((_:String).length ∙ (_:Int).toString ∙ ((_:Int) + 6))(5) |
∘ | 2218 | map | (((_:Int) + 6) ∘ (_:Int).toString ∘ (_:String).length)(5) |
∘∘ |
This file contains 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
/** | |
* <b>Fixed Point Combinator is:</b> | |
* Y = λf.(λx.f (x x)) (λx.f (x x)) | |
* | |
* <b>Proof of correctness:</b> | |
* Y g = (λf . (λx . f (x x)) (λx . f (x x))) g (by definition of Y) | |
* = (λx . g (x x)) (λx . g (x x)) (β-reduction of λf: applied main function to g) | |
* = (λy . g (y y)) (λx . g (x x)) (α-conversion: renamed bound variable) | |
* = g ((λx . g (x x)) (λx . g (x x))) (β-reduction of λy: applied left function to right function) | |
* = g (Y g) (by second equality) [1] |
This file contains 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
$ ghci | |
GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
Prelude> :l hello-ski.hs | |
[1 of 1] Compiling Main ( hello-ski.hs, interpreted ) | |
Ok, modules loaded: Main. | |
*Main> main | |
Hello world! |
This file contains 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
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] = { |
This file contains 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
// Updated for Scala 2.10.0. | |
def kind[A: scala.reflect.runtime.universe.TypeTag](a: A): String = { | |
import scala.reflect.runtime.universe._ | |
def typeKind(sig: Type): String = sig match { | |
case PolyType(params, resultType) => | |
(params map { p => | |
typeKind(p.typeSignature) match { | |
case "*" => "*" | |
case s => "(" + s + ")" | |
} |
This file contains 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
### 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: |
This file contains 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 scalaz._, Scalaz._ | |
case class Happy[A](a: A) | |
case class NewYear(year: Int) | |
implicit val happyInstance = new Applicative[Happy] { | |
def point[A](a: ⇒ A) = Happy(a) | |
def ap[A, B](fa: ⇒ Happy[A])(f: ⇒ Happy[A => B]) = | |
f match { | |
case Happy(f) ⇒ fa match { |
This file contains 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
> shapeless-core/console | |
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist | |
[info] Compiling 24 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes... | |
[info] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.11.0-20130205-141957-132e09fc2e (OpenJDK 64-Bit Server VM, Java 1.7.0_09). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._ |
This file contains 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
> 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. |
This file contains 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
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) |
NewerOlder