Haskell——模式匹配和Guard的区别
sayMe :: (Integral a) => a -> String
sayMe 1 = "One"
sayMe 2 = "Two"
sayMe 3 = "Three"
sayMe 4 = "Four"
sayMe x = "Others"
sayMe :: (Integral a) => a -> String
sayMe x
| x < 3 = "less than 3"
| x == 3 = "equals with 3"
| x > 3 = "larger than 3"
区别就在于一个对比的是对象,一个对比的是布尔值。