Real World Haskell - 第3章 Part9 The offside rule and white space in an expression
Real World Haskell で Haskell を継続的に勉強中。
Defining Types, Streamlining Functions
Chapter 3. Defining Types, Streamlining Functions
The offside rule and white space in an expression
- Haskell はインデントでブロックを区別する
- 移植性を考えてインデントに tabs は使わず spaces にすべし
-- This is the leftmost column. -- It's fine for top-level declarations to start in any column... firstGoodIndentation = 1 -- ...provided all subsequent declarations do, too! secondGoodIndentation = 2
-- This is the leftmost column. -- Our first declaration is in column 4. firstBadIndentation = 1 -- Our second is left of the first, which is illegal! secondBadIndentation = 2
- 括弧を使ってレイアウトしてもよい
bar = let a = 1 b = 2 c = 3 in a + b + c foo = let { a = 1; b = 2; c = 3 } in a + b + c