myFst :: (t,t1) -> t
myFst (a,_) = a
mySnd :: (t,t1) -> t
mySnd (a,_) = a
myNull::Int -> Bool
myNull x
| x < 0 = False
| otherwise = True
myEqu :: (Eq a) => a -> a -> Bool
myEqu x y = x == y
myElem :: (Eq a) => a -> [a] -> Bool
myElem x y | y == [] = False
| otherwise = x == (head y ) || (myElem x
(tail y ) )
--模式匹配
sayMe :: (Integral a ) => a -> String
sayMe 1 = "one"
sayMe 2 = "tow"
sayMe 3 = "three"
sayMe 4 = "four"
sayMe 5 = "five"
sayMe 6 = "six"
sayMe x = "just search"
addVectors :: (Num a) => (a,a) -> (a,a) -> (a,a)
addVectors (a,b) (c,d) = (a + b, c + d )
--putStr 输出
myHead :: [a] -> a
myHead [] = error "Can't call head on an empty list,
dummy"
myHead (x:_) = x
tell :: (Show a) => [a] -> String
tell [] = "The list is Empty"
tell (x:[]) = "The list has one element: " ++ show x
tell (x:y:[]) = "The list has two elements: " ++ show
x ++ " and " ++ show y
tell (x:y:z:[]) = "The list has third elements: " ++
show x ++ " , " ++ show y ++ " and " ++ show z
myLength :: (Num b) => [a] -> b
myLength [] = 0
myLength (_:xs) = 1 + myLength(xs)
--as模式
capital :: String -> String
capital "" = "empty, dummy"
capital all@(x:xs) = "The first letter of String " ++
all ++ " is x"
myFst (a,_) = a
mySnd :: (t,t1) -> t
mySnd (a,_) = a
myNull::Int -> Bool
myNull x
| x < 0 = False
| otherwise = True
myEqu :: (Eq a) => a -> a -> Bool
myEqu x y = x == y
myElem :: (Eq a) => a -> [a] -> Bool
myElem x y | y == [] = False
| otherwise = x == (head y ) || (myElem x
(tail y ) )
--模式匹配
sayMe :: (Integral a ) => a -> String
sayMe 1 = "one"
sayMe 2 = "tow"
sayMe 3 = "three"
sayMe 4 = "four"
sayMe 5 = "five"
sayMe 6 = "six"
sayMe x = "just search"
addVectors :: (Num a) => (a,a) -> (a,a) -> (a,a)
addVectors (a,b) (c,d) = (a + b, c + d )
--putStr 输出
myHead :: [a] -> a
myHead [] = error "Can't call head on an empty list,
dummy"
myHead (x:_) = x
tell :: (Show a) => [a] -> String
tell [] = "The list is Empty"
tell (x:[]) = "The list has one element: " ++ show x
tell (x:y:[]) = "The list has two elements: " ++ show
x ++ " and " ++ show y
tell (x:y:z:[]) = "The list has third elements: " ++
show x ++ " , " ++ show y ++ " and " ++ show z
myLength :: (Num b) => [a] -> b
myLength [] = 0
myLength (_:xs) = 1 + myLength(xs)
--as模式
capital :: String -> String
capital "" = "empty, dummy"
capital all@(x:xs) = "The first letter of String " ++
all ++ " is x"