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

TypedCoffeeScriptって、あったらよくないですか

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 TypedCoffeeScriptって、あったらよくないですか

altjs武闘会

Avatar for Koutarou Chikuba

Koutarou Chikuba

June 08, 2014
Tweet

More Decks by Koutarou Chikuba

Other Decks in Technology

Transcript

  1. CoffeeScript:,ؔ਺ {sqrt, pow} = Math distance = (from, to) ->

    sqrt pow(from.x - to.x, 2) + pow(from.y - to.y, 2) console.log distance {x: 0, y: 0}, {x: 3, y: 4} #=> 5
  2. TypedCoffeeScript:/ؔ਺ sqrt :: Number * Number -> Float pow ::

    (Number, Number) -> Float {sqrt, pow} = Math distance :: Point * Point -> Float distance = (from, to) -> sqrt pow(from.x - to.x, 2) + pow(from.y - to.y, 2) console.log distance {x: 0, y: 0}, {x: 3, y: 4} #=> 5
  3. TypedCoffeeScript:/ؔ਺ foo = Int -> Int -> Int foo =

    (m) -> (n) -> m * n n :: Int = foo(3)(2) ͜Μͳ͜ͱ΋
  4. Structual(Subtyping struct Point {x :: Int, y :: Int} p

    :: Point = {x: 1, y: 2, z: 3} n :: Int = p.z # type error p3d :: {x :: Int, y :: Int, z :: Int} = p # type error • ୅ೖઌ͕αϒΫϥεͰ͋Δ͜ͱΛཁٻ͢Δ • ܕΞϊςʔγϣϯ͕એݴ͞ΕͨγϯϘϧ(ม਺)͸Ҏ߱ͦͷΠϯλ ʔϑΣʔεͰৼΔ෣͏
  5. ઃܭࢦ਑ • ܕΞϊςʔγϣϯߏจΛ௥Ճ • ੩తղੳ • ίϯύΠϥʹ͸ۃྗखΛೖΕͳ͍(Ϛʔδ͕ࠔ೉ʹͳΔͨΊ) • ίϯύΠϥͱ͸ผʹAST'TraverserΛॻ͘ •

    ϊʔυ͝ͱʹtypeAnnota2onΛղܾ͢Δܕਪ࿦ثΛ࡞Δ ઃܭํ਑:"ݎ࿚ͳઃܭ"<"طଘίʔυ͔ΒͷҠߦίετ࠷খԽ