From Javascript To Haskell

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    From Javascript To Haskell - Presentation Transcript

    1. JavaScript Haskell 2008-01-24 UJIHISA, Tatsuhiro
    2. who's this? • ujihisa • Osaka Univ. M2 • Fuzzy Rough Sets • nayutaya - http://www.nayutaya.co.jp • LiveCoding, ldev, Haskell, On Lisp...
    3. from js to hs
    4. Ruby natural class-based OO prototype-based JavaScript OO, functional Haskell simple functional
    5. simplicity • process serially • assignment • loop • implicit cast
    6. simplicity • process serially • assignment • loop • implicit cast
    7. no variables var a = 1; var b = function() { return 1 }; a = 1 b = 1
    8. no re-assignment var a = 1; var a = 2; a = 1 a = 2 -- Multiple declarations of `Main.a'
    9. var f = function() { var i = 0; return function() { return i++; } }; var g = f(); g(); //=> 0 g(); //=> 1 g(); //=> 2 g(); //=> 3 g(); //=> 4
    10. principle
    11. write less code • principle: as possible as you should write less code • development, maintenance, ...always.
    12. notation
    13. aaa(bbb(\"hahaha\", 3))); aaa (bbb \"hahaha\" 3) aaa $ bbb \"hahaha\" 3
    14. window.addEventListener( \"load\", function() { alert(\"a\") }) main = putStrLn \"a\"
    15. var f = function(a, b) { return a + b }; f(8, 7) //=> 15 f a b = a + b f 8 7 -- 15
    16. var f = function(a) { var g = function(b) {...}; return g(a); }; f a = g a where g b = ...
    17. var fib = function(n) { return (n == 1) ? 1 : (n == 2) ? 1 : fib(n-2) + fib(n-1); }; fib 1 = 1 fib 2 = 1 fib n = fib (n-2) + fib (n-1)
    18. (function(a) { return a + 1 }) (function(a) { return a + 1 })(3) //=> 4 (\\a -> a + 1) (\\a -> a + 1) 3 -- 4
    19. a + b (+) a b add a b a `add` b
    20. List Processing Haskell vs JavaScript with prototype.js
    21. [1, 2, 3].map(function(i) { return i + 1; }) //=> [2, 3, 4] map (\\i -> i + 1) [1, 2, 3] -- [2, 3, 4]
    22. [1, 2, 3, 4, 5].first() //=> 1 [1, 2, 3, 4, 5][3] //=> 4 head [1, 2, 3, 4, 5] -- 1 [1, 2, 3, 4, 5] !! 3 -- 4
    23. $R(1, 10).toArray() //=> [1, 2, ..., 10] $R(1, Infinity).toArray() //... [1..10] [1..]
    24. head [1..] -- 1 head tail [1..] -- 2 [1..] !! 10 -- 11
    25. curry
    26. var f = function(a) { return function(b) { return function(c) { return a + b + c }}}; f(3)(5)(7) //=> 15 f a b c = a + b + c f a b = (\\c -> a + b + c) f a = (\\b -> (\\c -> a + b + c)) f = (\\a -> (\\b -> (\\c -> a + b + c))) f 3 5 7 -- 15
    27. f a b = a + b f a b = (+) a b f = (+) addOne a = 1 + a addOne a = (+) 1 a addOne = (+) 1 addOne = (1 +) map (1 +) [1, 2, 3]
    28. list comprehension
    29. tmp = []; [1, 2].each(function(x) { [10, 20].each(function(y) { tmp.push(x + y) }) }); [ x + y | x <- [1, 2], y <- [10, 20]] {x + y|x ∈ X, y ∈ Y }
    30. tmp = []; $R(1, Infinity).each(function(x) { if (x % 2 == 0 && x < 10) { tmp.push(x) } }); [ x | x <- [1..], x `mod` 2 == 0, x < 10] {x|x ∈ N, x ≡ 0 mod 2, x < 10}
    31. fib again h (+) fib (tail fib) fib = 1 : 1 : zipWit
    32. how to use • sudo port install ghc • HotMac :-) • runghc a.hs • ghc a.hs && ./a.out • ghci
    33. for what? • draft • step up • production
    34. Monadius
    35. HSP
    36. Haskell Scheme Prolog
    37. • lazy evaluation • monad • type inference
    38. thank you!

    + ujihisaujihisa, 2 years ago

    custom

    2559 views, 2 favs, 0 embeds more stats

    Kanasan.JS - JS#2

    More Info

    © All Rights Reserved

    Go to text version
    • Total Views 2559
      • 2559 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 30
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as innappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel

    Categories