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

PureScript

 PureScript

For Full Stack Boulder.

Brian McKenna

May 19, 2014
Tweet

More Decks by Brian McKenna

Other Decks in Programming

Transcript

  1. data Person = Person String Number sayHello :: Person ->

    String sayHello (Person name age) = "Hello " ++ name ++ ", you are " ++ show age ++ " years old"
  2. var PS = PS || {}; PS.Person = (function ()

    { "use strict"; var Prelude = PS.Prelude; var Person = function (value0) { return function (value1) { return { ctor: "Person.Person", values: [ value0, value1 ] }; }; }; var sayHello = function (_1) { return "Hello " + _1.values[0] + ", you are " + Prelude.show(Prelude.showNumber({}))(_1.values[1]) + " years old"; }; return { Person: Person, sayHello: sayHello }; })();
  3. addXY :: forall r. { x :: Number, y ::

    Number | r } -> Number addXY o = o.x + o.y -- Error: Object does not have property y -- x :: Number -- x = addXY { x: 1 } xy :: Number xy = addXY { x: 1, y: 2 } xyz :: Number xyz = addXY { x: 1, y: 2, z: 3 }
  4. class ToString s where toString :: s -> String instance

    boolTS :: ToString Boolean where toString = showBool instance numberTS :: ToString Number where toString = showNumber main = trace (toString true ++ toString 10)
  5. module.exports = function(grunt) { grunt.initConfig({ libFiles: [ "src/**/*.purs", "bower_components/purescript-*/src/**/*.purs", ],

    clean: ["output"], pscMake: ["<%=libFiles%>"], dotPsci: ["<%=libFiles%>"], docgen: { readme: { src: "src/**/*.purs", dest: "README.md" } } }); grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-purescript"); grunt.registerTask("make", ["pscMake", "dotPsci", "docgen"]); grunt.registerTask("default", ["make"]); };
  6. { "name": "purescript-streams", "homepage": "https://github.com/purescript-contrib/purescript-streams", "description": "Compositional, streaming I/O library",

    "keywords": [ "purescript" ], "license": "MIT", "ignore": [ "**/.*", "bower_components", "node_modules", "output", "tests", "tmp", "bower.json", "Gruntfile.js", "package.json" ], "dependencies": { "purescript-monoid": ">=0.1.1", "purescript-tuples": "*", "purescript-task": "*" } }
  7. counter = mkUI spec { getInitialState = return 0 }

    do val <- readState return $ DOM.p { className: "Counter", onClick: handle incrementCounter } [ DOM.text (show val), DOM.text " Click me to increment!" ]
  8. testConst :: Number -> Number -> Number -> Boolean testConst

    a b c = const a b == const a c main :: Eff (trace :: Trace) {} main = quickCheck testConst
  9. snowflake :: Number -> Drawing snowflake n = go <<<

    go <<< go $ circle where go = everywhere replace replace (Arc { cx = cx, cy = cy, r = r }) = Composite $ flip map (range 0 (n - 1)) $ \i -> let theta = i / n * Math.pi * 2 in Arc { cx: cx + r * 0.7 * Math.sin theta , cy: cy + r * 0.7 * Math.cos theta , r: r * 0.3 , start: 0 , end: Math.pi * 2 } replace other = other
  10. sayHello :: Process (Task (trace :: Trace)) {} sayHello =

    await (traceTask "Hello") (const Halt) main :: Eff (trace :: Trace) {} main = runTask (Process.run (repeatedly sayHello))