Skip to content
View gist:ed7443d6d1f339e61e95
*ghci> g
Game {, [Josh rack: HXDOTQI score: 0id: 0] :| [[Nick rack: KGAITTE score: 0id: 1]], ______________________________________________
|3W| | |2L| | | |3W| | | |2L| | |3W|
| |2W| | | |3L| | | |3L| | | |2W| |
| | |2W| | | |2L| |2L| | | |2W| | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
| | | | |2W| | | | | |2W| | | | |
| |3L| | | |3L| | | |3L| | | |3L| |
| | |2L| | | |2L| |2L| | | |2L| | |
|3W| | |2L| | | | *| | | |2L| | |3W|
View scrabble.ghci
$ stack ghci
*ghci> import Data.Aeson
*ghci> let g = unsafeNewGame [human "josh"]
*ghci> let g = unsafeNewGame [human "josh", human "nick"]
*ghci> g
Game {, [[josh rack: DOERUTO score: 0id: 0],[nick rack: ELIALIH score: 0id: 1]], ______________________________________________
|3W| | |2L| | | |3W| | | |2L| | |3W|
| |2W| | | |3L| | | |3L| | | |2W| |
| | |2W| | | |2L| |2L| | | |2W| | |
|2L| | |2W| | | |2L| | | |2W| | |2L|
View Mappy.scala
import scala.language.higherKinds
import scalaz.{Applicative, Traverse}
import scalaz.\/
import scalaz.std.list._
import scalaz.std.option._
import scalaz.syntax.either._
import scalaz.syntax.traverse._
object Mappy {
View HowDoICallEval.scala
//libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.2.0"
import scala.language.higherKinds
import scalaz.{MonadState, MonadListen, MonadReader, MonadError, \/}
import scalaz.std.list._
// All I want to do in this code is invoke the eval function. That's it.
// This code compiles, so it's close, just needs the finishing touch.
object HowDoICallEval {
View ExploringLookups.md

Let's say I want to look something up in an environment (like Map String Int or something, doesn't really matter). I start with Reader for the Env, and I use the ask function.

type Env = Map String Int

envLookup :: String -> Reader Env Int
envLookup key = (Maybe.fromMaybe (error "unbound var") . Map.lookup key) <$> ask
View writerreader.scala
type R[A] = Reader[Env, A]
type Z[F[_], A] = WriterT[F, Output, A]
type W[A] = Z[R, A]
def evalLocal(x: String, i: Int, exp: Exp): W[Int] = {
WriterT[R,Output,Int](
Reader[Env, (Output, Int)] { (env: Env) =>
eval(exp).run.run(env + (x -> i))
}
)
View gist:cd57998ef2bd51d5e202
scala> import scalaz.syntax._, validation._, either._, monadPlus._
import scalaz.syntax._
import validation._
import either._
import monadPlus._
scala> import scalaz.std.list._
import scalaz.std.list._
scala> List(1.left, 2.left, "bad".right, "really bad".right).separate
View gist:bc9050a42630008b1eed
object LetLangError {
import scala.language.higherKinds
import scalaz.MonadError
import scalaz.syntax.monad._
import scalaz.syntax.monadError._
trait Exp
case class Num(i:Int) extends Exp
case class Add (l:Exp, r:Exp) extends Exp
Something went wrong with that request. Please try again.