Seven More Languages in Seven Weeks (读书笔记):Elm

来源:互联网 发布:wordpress搬家换域名 编辑:程序博客网 时间:2024/04/28 17:20

Elm

  1. Day 1
    1. > [1, "2"] //强类型,要求数组内元素必须是同一个类型?
    2. Building Algebraic Data Types:> type Color = Black | White //Haskell语法?
      1. type List = Nil | Cons Int List
      2. type List a = Empty | Cons a (List a)
    3. Using Records
      1. > blackQueen = {color=Black, piece=Queen}
      2. > .color blackQueen //这是学习的Clojure?
    4. 函数
      1. > add x y = x + y
      2. > anonymousInc = \x -> x + 1
      3. > 5 |> anonymousInc |> double //这是学习的Elixir?
        1. > double <| anonymousInc <| 5
    5. 模式匹配
      1. 简化函数定义:> first (head::tail) = head
  2. Day 2
    1. 信号:A signal represents I/O as a value that varies over time(stream?Rx Observable?)
      1. main = Signal.map show Mouse.position
      2. count signal = Signal.foldp (\_ n -> n + 1) 0 signal
    2. 组合信号
      1. clickPosition = Signal.sampleOn Mouse.clicks Mouse.position //当clicks更新时采样position
  3. Day 3
    1. games/skeleton.elm
      1. delta = inSeconds <~ fps n
      2. input = sampleOn delta (...)
      3. main = map display gameState
      4. gameState = foldp stepGame initialGameState input

0 0
原创粉丝点击