Hello everyone! My name is Sanjiv. Welcome to our presentation on using Types for Quality. There will be four presentations followed by some time for questions and answers at the end. First off, we have Luke, who will talk to us about some common problems faced when developing software. Over to you Luke.
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 sys.process._ | |
val com = inputKey[Unit]("Run an external command") | |
import complete.DefaultParsers._ | |
com := { | |
val args: Seq[String] = spaceDelimited("external command. eg. ls -l .").parsed | |
val command = Seq("sh", "-c", s"${args.mkString(" ")}") | |
val pl = ProcessLogger(println(_), e => println(s"""\033[31m$e""")) |
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
//put in ~/.sbt/1.0/global.sbt if you want this to be the default shell everywhere | |
import scala.sys.process._ | |
import scala.util.Try | |
shellPrompt := { s: State => | |
val extracted = Project.extract(s) | |
val devNull = ProcessLogger(_ => ()) |
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
package com.example.circe | |
import io.circe._ | |
import io.circe.parser._ | |
object HelloWorld { | |
val deprecatedKeys = Vector("foo") | |
def main(args: Array[String]) { |
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
//Throwable | |
// - Error //never catch | |
// - Exception //"checked" in Java | |
// - RuntimeException // "unchecked in Java | |
class NotAnIntException(message: String) extends Exception(message) | |
def strToInt(value: String): Int = | |
if (value.forall(_.isDigit)) value.toInt |
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
//definition of Either | |
sealed trait Either[+A, +B] | |
case class Left[A](a: A) extends Either[A, Nothing] | |
case class Right[B](b: B) extends Either[Nothing, B] | |
//whiteboard | |
//Right -> Results | |
//Left -> Errors |
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
//Currying is the process of transforming a function that takes multiple arguments into a | |
//function that takes just a single argument and returns another function if any arguments are still needed. | |
def curriedAdd2: Int => Int => Int = x => y => x + y | |
:t curriedAdd2 | |
//Int => (Int => Int) | |
curriedAdd2(5) |
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
-- | Main entry point to the application. | |
module Main where | |
import Control.Monad.Reader | |
import Control.Monad.Writer | |
{- | |
The ReaderT transformer is used to retrieve a read-only value from some environment. | |
The WriterT transformer will log the result of each retrieval. | |
Running the two transformers together yields a log of each step along with the actual results. |
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
{-# LANGUAGE TypeSynonymInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
module Sample(perform, runAsIO, runAsSt) where | |
import Text.Printf (printf) | |
import qualified Control.Monad.Trans.State as S | |
class Monad m => ConsoleR m where | |
writeLine :: String -> m () |