2016年4月20日水曜日

開発環境

Seven More Languages in Seven Weeks (Bruce Tate (著)、Ian Dees (著)、Frederic Daoud (著)、Jack Moffitt (著)、Pragmatic Bookshelf)のChapter 3(Elm)、Day 1(Handling the Basics)、Do (Easy)(No. 3034).を取り組んでみる。

Do (Easy)(No. 3034)

入出力結果(Emacs, Terminal, elm repl)

$ elm-repl 
---- elm repl 0.16.0 -----------------------------------------------------------
 :help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> product list = case list of \
|   [] -> 1 \
|   head::tail -> head * product tail
<function> : List number -> number
> product [1..10]
3628800 : number
> xFields points = case points of \
|   [] -> [] \
|   head::tail -> head.x::xFields tail
<function> : List { b | x : a } -> List a
> xFields [{x=5, y=0}, {x=1, y=0}, {x=4, y=0}, {x=2, y=0}, {x=3, y=0}]
[5,1,4,2,3] : List number
> person = {name="elm", age=10, address={country="Japan", state="Tokyo"}}
{ name = "elm", age = 10, address = { country = "Japan", state = "Tokyo" } }
    : { address : { country : String, state : String }
      , age : number
      , name : String
      }
> person
{ name = "elm", age = 10, address = { country = "Japan", state = "Tokyo" } }
    : { address : { country : String, state : String }
      , age : number
      , name : String
      }
> person.name
"elm" : String
> person.address
{ country = "Japan", state = "Tokyo" } : { country : String, state : String }
> person.address.country
"Japan" : String
> person.address.state
"Tokyo" : String
> :exit
$

0 コメント:

コメントを投稿