#Monoid in Scala by programmers from different backgrounds#
In spirit of The Evolution of a Haskell Programmer. Originally stolen from isoresursive.
> 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._ |
> core/console | |
[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_17). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import scalaz._ | |
import scalaz._ |
BUILD SUCCESSFUL | |
Total time: 9 minutes 21 seconds | |
Welcome to Scala version 2.11.0-20130329-204437-40d2981c24 (OpenJDK 64-Bit Server VM, Java 1.7.0_17). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :kind scala.Option | |
Option's kind is * -> * | |
scala> :k scalaz.Unapply |
// 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 + ")" | |
} |
scala> import scalaz._ | |
import scalaz._ | |
scala> import std.option.optionFirst | |
import std.option.optionFirst | |
scala> import syntax.monoid._ | |
import syntax.monoid._ | |
scala> import Isomorphism._ |
type State[E] = Adjunction[({type λ[α] = Writer[E, α]})#λ, ({type λ[α] = Reader[E, α]})#λ] | |
type Store[E] = Adjunction[({type λ[α] = Reader[E, α]})#λ, ({type λ[α] = Writer[E, α]})#λ] | |
type Cont = Adjunction[Function0, Function0] // Function0 -| Function0 |
#Monoid in Scala by programmers from different backgrounds#
In spirit of The Evolution of a Haskell Programmer. Originally stolen from isoresursive.
> 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.SingletonTypes._ |
> 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._ |
shapeless [0849b6f...] % sbt | |
[info] Loading project definition from /home/folone/workspace/shapeless/project | |
[info] Set current project to shapeless (in build file:/home/folone/workspace/shapeless/) | |
> shapeless-core/console | |
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist | |
[info] Compiling 2 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes... | |
[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). |