[Learning You a Haskell for Great Goods!] chapter 02 believe the type

Haskell has type inference

 

function declaration

methodname :: [input type] -> [return type]

or

methodname :: [input type] -> [input type] -> [input type] -> [return type]

 

check type

ghci> :t 'a'

'a' :: Char

 

ghci> :t (+)

(+) :: Num a => a -> a -> a

class constraint

 

show & read

ghci> :t show

show :: Show a => a -> String

 

ghci> :t read

read :: Read a => String -> a

 

ghci> read "5" :: Int

5

 

if haskell could interfer the type , then no need to declaration

posted @ 2014-09-24 14:48  映天蓝  阅读(99)  评论(0)    收藏  举报