Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's talk about PureScript

Let's talk about PureScript

Presentation at Frontend Meetup Riga, August 2016.

Kārlis Lauva

August 17, 2016
Tweet

More Decks by Kārlis Lauva

Other Decks in Programming

Transcript

  1. Hello. I write Clojure and dabble with other things This

    is not a monad tutorial This is, like, my opinion
  2. module Main where import Prelude import Control.Monad.Eff import Control.Monad.Eff.Console sup

    :: String -> String sup g = "sup, " ++ g main :: forall e. Eff (console :: CONSOLE | e) Unit main = do log $ sup "world"
  3. (function(exports) { "use strict"; var Prelude = PS["Prelude"]; var Control_Monad_Eff

    = PS["Control.Monad.Eff"]; var Control_Monad_Eff_Console = PS["Control.Monad.Eff.Console"]; var sup = function (g) { return "sup, " + g; }; var main = Control_Monad_Eff_Console.log(sup("world")); exports["main"] = main; exports["sup"] = sup;; })(PS["Main"] = PS["Main"] || {}); PS["Main"].main();
  4. Y

  5. data Behavior = KillHumans | BeNiceToHumans type Robot = {

    naughty :: Boolean } interactWithHumans :: Robot -> Behavior interactWithHumans { naughty: true } = KillHumans interactWithHumans { naughty: false } = BeNiceToHumans
  6. data Behavior = KillAllHumans | BeNiceToHumans | KillOnlyVapers type Robot

    = { niceness :: Int } interactWithHumans :: Robot -> Behavior interactWithHumans { niceness: 0 } = KillAllHumans interactWithHumans { niceness: 1 } = KillOnlyVapers interactWithHumans _ = BeNiceToHumans
  7. data RobotArmy = Army (List Robot) fetchRobots = do robotParts

    <- get "/robotParts" robots <- assembleFleet robotParts return $ Army robots
  8. data Behavior = KillHumans | BeNiceToHumans instance showBehavior :: Show

    Behavior where show KillHumans = "kill all humans11" show BeNiceToHumans = "humans, you are pretty tite" type Robot = { naughty :: Boolean } interactWithHumans :: Robot -> Behavior interactWithHumans { naughty: true } = KillHumans interactWithHumans { naughty: false } = BeNiceToHumans safeInteract :: Boolean -> String safeInteract x = show $ interactWithHumans { crazyMurderer : x }