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 飞林沙 阅读(214) 评论(0) 编辑 收藏
发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 1990909 586uXn04ZrU=