Notes from @shalinpei and @llewrek.
- 2 rooms, one lab and one observation
- Observation room
- One-way mirror
- Tables
Notes from @shalinpei and @llewrek.
List(1,2,3,4,5).foldRight(List.empty[Int])(_ :: _) | |
//res1: List[Int] = List(1, 2, 3, 4, 5) | |
/* | |
Passing in the type constructors for an abstract data type to its fold method | |
is the identity function. | |
List is made up of `Nil` and `Cons` objects. | |
*/ |
// Add `libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.5"` to build.sbt | |
// Run `sbt console` | |
:paste | |
import scalaz._, Scalaz._ | |
case class Config(val a: Int) | |
def run: Reader[Config, String] = for { | |
a <- foo |
/*** Setting up the abstract data type (ADT) / algebra for a linked list ***/ | |
sealed trait List[+A] | |
case object Nil extends List[Nothing] | |
case class Cons[+A](head: A, tail: List[A]) extends List[A] | |
/*** Defining `fold` which is a catamorphism ***/ | |
// Catamorphism is essentially a reducing traversal of the data | |
// using pattern matching? |
sealed trait Player | |
case object Player1 extends Player | |
case object Player2 extends Player | |
sealed trait GameWinner extends Player | |
case object Tie extends GameWinner | |
sealed trait Position | |
case object TopLeft extends Position | |
case object TopCenter extends Position |
http://www.cs.uoregon.edu/research/summerschool/summer13/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer12/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer11/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer10/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer09/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer08/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer07/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer06/curriculum.html http://www.cs.uoregon.edu/research/summerschool/summer05/curriculum.html
scala> val task = Task.delay({ println("running"); 42}) | |
task: scalaz.concurrent.Task[Int] = scalaz.concurrent.Task@13283317 | |
scala> task.run | |
running | |
res37: Int = 42 |
:paste | |
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return} | |
// Console grammar | |
sealed trait ConsoleF[+A] | |
object Console { | |
case class WriteLine[A](msg: String, o: A) extends ConsoleF[A] | |
case class ReadLine[A](o: String => A) extends ConsoleF[A] | |
} |
// import Control.Monad.Free | |
// import System.Exit hiding (ExitSuccess) | |
:paste | |
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return, liftF} | |
// data TeletypeF x | |
// = PutStrLn String x | |
// | GetLine (String -> x) |
// Requires scalaz 7.1.0 or later | |
:paste | |
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return, liftF} | |
sealed trait TeletypeF[+A] | |
case class PutStrLn[A](msg: String, o: A) extends TeletypeF[A] | |
case class GetLine[A](o: String => A) extends TeletypeF[A] | |
implicit def teletypeFFunctor[B]: Functor[TeletypeF] = new Functor[TeletypeF] { |