対話モードで複数行入力する方法
ghci> :{
ghci| lucky :: (Integral a) => a -> String
ghci| lucky 7 = "LUCKY NUMBER SEVEN!"
ghci| lucky x = "Sorry, you're out of luck, pal!"
ghci| :}
ghci> lucky 7
"LUCKY NUMBER SEVEN!"
ghci> lucky 8
"Sorry, you're out of luck, pal!" scrap
Haskellを学んだときのあれこれの雑書きと後で調べるようのメモ
ghci> :{
ghci| lucky :: (Integral a) => a -> String
ghci| lucky 7 = "LUCKY NUMBER SEVEN!"
ghci| lucky x = "Sorry, you're out of luck, pal!"
ghci| :}
ghci> lucky 7
"LUCKY NUMBER SEVEN!"
ghci> lucky 8
"Sorry, you're out of luck, pal!" haskell では、Rust と違って網羅する必要がなく、その他は otherwise でまとめられる
Rust でいう _ のようなもの
bmiTell :: (RealFloat a) => a -> String
bmiTell bmi
| bmi <= 18.5 = "You're underweight, you emo, you!"
| bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise = "You're a whale, congratulations!" Notebook LMに、
4 Declarations and Bindings
を元に掲題についての回答
んーよくわからん
cylinder :: (RealFloat a) => a -> a -> a
cylinder r h = sideArea + 2 * topArea
where sideArea = 2 * pi * r * h
topArea = pi * r^2cylinder :: (RealFloat a) => a -> a -> a
cylinder r h =
let sideArea = 2 * pi * r * h
topArea = pi * r ^2
in sideArea + 2 * topArea