天天看點

Seven More Languages in Seven Weeks (讀書筆記):Elm

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

繼續閱讀