すごいHaskell本

第3章を進めております。

関数を定義する際、引数の構造で場合分けするときにはパターンを使います。
引数の値が満たす性質で場合分けするときには、ガードを使います。

ふつうのHaskell本を読んでたときは、パターンマッチとガードの違いがよく分からな
かったので、上の解説は助かります。

p42の bmiTell を -Wall -Werror オプション付きで実行するとエラーが出るんですが、こ
れは何なのでしょうね。

bmiTell :: Double -> Double -> String
bmiTell weight height
  | weight / height ^ 2 <= 18.5 = "You're underweight, you emo, you!"
  | weight / height ^ 2 <= 25.0 = "You're supposedly normal.\
                    \ Pffft, I bet you're ugly!"
  | weight / height ^ 2 <= 30.0 = "You're fat! Lose some weight, fatty!"
  | otherwise   = "You're a whale, congratulations!"
chap3.hs:49:21:
    Warning: Defaulting the following constraint(s) to type `Integer'
               (Integral b0) arising from a use of `^' at chap3.hs:49:21
               (Num b0) arising from the literal `2' at chap3.hs:49:23
    In the second argument of `(/)', namely `height ^ 2'
    In the first argument of `(<=)', namely `weight / height ^ 2'
    In the expression: weight / height ^ 2 <= 18.5

chap3.hs:50:21:
    Warning: Defaulting the following constraint(s) to type `Integer'
               (Integral b0) arising from a use of `^' at chap3.hs:50:21
               (Num b0) arising from the literal `2' at chap3.hs:50:23
    In the second argument of `(/)', namely `height ^ 2'
    In the first argument of `(<=)', namely `weight / height ^ 2'
    In the expression: weight / height ^ 2 <= 25.0

chap3.hs:52:21:
    Warning: Defaulting the following constraint(s) to type `Integer'
               (Integral b0) arising from a use of `^' at chap3.hs:52:21
               (Num b0) arising from the literal `2' at chap3.hs:52:23
    In the second argument of `(/)', namely `height ^ 2'
    In the first argument of `(<=)', namely `weight / height ^ 2'
    In the expression: weight / height ^ 2 <= 30.0