Skip to content

Instantly share code, notes, and snippets.

Usability Lab Notes

Notes from @shalinpei and @llewrek.

Notes

  • 2 rooms, one lab and one observation
  • Observation room
    • One-way mirror
    • Tables
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?
@danclien
danclien / tictactoeapi.scala
Last active August 29, 2015 13:57
Quick attempt at Tony Morris's tic-tac-toe API exercise from http://blog.tmorris.net/posts/scala-exercise-with-types-and-abstraction/index.html.
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
scala> val task = Task.delay({ println("running"); 42})
task: scalaz.concurrent.Task[Int] = scalaz.concurrent.Task@13283317
scala> task.run
running
res37: Int = 42
@danclien
danclien / scalaz_console_io_free_monad.scala
Last active August 29, 2015 13:57
Attempt to write a monad for console IO using scalaz's Free monad
: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] {