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
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
// 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 |
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
/*** 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? |
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
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 |
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
scala> val task = Task.delay({ println("running"); 42}) | |
task: scalaz.concurrent.Task[Int] = scalaz.concurrent.Task@13283317 | |
scala> task.run | |
running | |
res37: Int = 42 |
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
: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] | |
} |
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 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) |
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
// 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] { |
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 Control.Monad.Reader | |
main :: IO () | |
main = runReaderT code 32 | |
code :: ReaderT Int IO () | |
code = do | |
x <- ask | |
liftIO $ print (x+10) | |
return () |
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 Control.Monad.State | |
type App = StateT String IO | |
main :: IO () | |
main = do | |
x <- runStateT code "" | |
print x -- ("stateResult","stateValue") | |
return () |