Haskell学习笔记--函数定义

Haskell学习笔记--函数定义

if 语句

signum :: Int -> Int
signum n = if n < 0 then -1 else 
                 if n==0 then 0 else 1

 

Guarded equtions

signum n  | n > 0 = 1
          | n < 0 = -1
          | otherwise = 0

 

模式匹配

True && True = True
_ && _ = False

head :: [a] -> a
head (x:_) = x

 

lambda expression

add = \x -> (\y -> x+y)

const :: a -> b -> a
const x =  \_ -> x 

这个还挺有用,主要是简洁

 

posted @ 2021-11-16 21:07  liankewei123456  阅读(52)  评论(0编辑  收藏  举报