Haskell——模式匹配和Guard的区别

sayMe :: (Integral a) => a -> String
sayMe 1 = "One"
sayMe 2 = "Two"
sayMe 3 = "Three"
sayMe 4 = "Four"
sayMe x = "Others"

 

image

sayMe :: (Integral a) => a -> String
sayMe x
    | x < 3 = "less than 3"
    | x == 3 = "equals with 3"
    | x > 3 = "larger than 3"

image

区别就在于一个对比的是对象,一个对比的是布尔值。

posted @ 2011-03-22 01:34  飞林沙  阅读(2132)  评论(0编辑  收藏  举报