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

The reason for using reason

mzp
July 22, 2017

The reason for using reason

mzp

July 22, 2017

Transcript

50 slides
  1. function counter(state = 0, action) { switch (action.type) { case

    'INCREMENT': return state + 1 case 'DECREMENT': return state - 1 default: return state } } ྫDPVOUFSSFEVDFS { type: "INCREMENTAL" }
  2. function todo(state, action) { switch (action.type) { case 'TOGGLE': if(state.id

    == action.id) { return {...state , completed: !state.completed } } else { return state } default: return state } } ྫUPEPSFEVDFS { type: 'TOGGLE', id: 42 } { id: 42, name: "create slide", completed: false, ... }
  3. JavaScript OCaml Flow Reason Adopting features of ML Becoming familiar

    to JS developers Syntax + tooling A lot of work Ҿ༻ݩ5IF%BXOPG3FBTPO IUUQTTBOEFSTQJFTHJUIVCJPTMJEFTEBXOPGSFBTPOQEG
  4. #VDLMF4DSJQUͱͷ࿈ܞ 0$BNM͔Β+BWB4DSJQUΛੜ੒͢ΔίϯύΠϥ IUUQHJUIVCDPNCMPPNCFSHCVDLMFTDSJQU function fact(n) { if (n !== 0)

    { return imul(n, fact(n - 1 | 0)); } else { return 1; } } let rec fact = function | 0 -> 1 | n -> n * fact (n - 1) 0$BNM +BWB4DSJQU
  5. 'use strict'; var Pervasives = require("bs-platform/lib/js/pervasives"); var Http = require("http");

    var hostname = "127.0.0.1"; function create_server(http) { var server = http.createServer(function (_, resp) { resp.statusCode = 200; resp.setHeader("Content-Type", "text/plain"); return resp.end("Hello world\n"); }); return server.listen(3000, hostname, function () { console.log("Server running at http://" + (hostname + (":" + (Pervasives.string_of_int(3000) + "/")))); return /* () */0; }); } create_server(Http); IVNBOSFBEBCMFDPEF
  6. switch data { | GoodResult theMessage => "Success! " ^

    theMessage | BadResult errorCode => "Something's wrong. The error code is: " ^ (string_of_int errorCode) }; จ๏ύλʔϯϚον
  7. let redux state = function | `Toggle id -> if

    state.id = id then { state with complete=not state.complete } else state | _ -> state ύλʔϯϚον࠷ߴ
  8. let maybeSay (s: string Js.null) = Js.Null.iter s (fun message

    -> Js.log message) let maybeSay (s: string Js.undefined) = Js.Undefined.iter s (fun message -> Js.log message) OVMMVOEFpOFE
  9. take_if context ~f:(function `DelayedInc -> Some () | _ ->

    None) >>= (fun () -> call (delay 1000)) >>= (fun () -> put context `Inc) DBMMCBDLIFMM
  10. external request : config -> response Js.Promise.t = "get" [@@bs.module

    "axios"]; external get : string -> config Js.null -> response Js.Promise.t = "get" [@@bs.module "axios"]; external delete: string -> config Js.null -> response Js.Promise.t = "delete" [@@bs.module "axios"]; external head: string -> config Js.null -> response Js.Promise.t = "head" [@@bs.module "axios"]; external post: string -> 'a Js.null -> config Js.null -> response Js.Promise.t = "post" [@@bs.module "axios"]; external put: string -> config Js.null -> response Js.Promise.t = "put" [@@bs.module "axios"]; external patch: string -> config Js.null -> response Js.Promise.t = "patch" [@@bs.module "axios"]; ܕఆ͕ٛେม
  11. let expect_array json = switch (Js.Json.reifyType json) { | Js.Json.Array,

    data -> swtich (Js.Json.reifyType data) { ... } | _ -> failwith "unexpected response type" } +40/͔ΒͷσʔλऔΓग़͠
  12. type tree = | Leaf | Node of int *

    tree * tree (* Leaf --> 0 *) (* Node(a,b,c) --> [a,b,c]*) όϦΞϯτͷϥϯλΠϜදݱ

More Decks by mzp

Other Decks in Technology