オンライン版(英語): http://learnyouahaskell.com/types-and-typeclasses
#SS2 型を信じろ! ##SS2-1 明示的な型宣言
:t 'a'
:t True
:t "HELLO!"
:t (True, 'a')
:t 4 == 5
sample1
removeNonUppercase :: [Char] -> [Char]
removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']]
sample2
addThree :: Int -> Int -> Int -> Int
addThree x y z = x + y + z
##SS2-2 一般的なHaskellの型
Int
Integer
Float
Double
Bool
Char
samples
factorial :: Integer -> Integer
factorial n = product [1..n]
circumference :: Float -> Float
circumference r = 2 * pi * r
circumference' :: Double -> Double
circumference' r = 2 * pi * r
##SS2-3 型変数
:t head
:t fst
##SS2-4 型クラス 初級講座 ###Eq Ord
:t (==)
5 == 5
5 /= 5
'a' == 'a'
"Ho Ho" == "Ho Ho"
3.432 == 3.432
:t (>)
"Abrakadabra" < "Zebra"
"Abrakadabra" `compare` "Zebra"
5 >= 2
5 `compare` 3
###Show Read
show 3
show 5.334
show True
read "True" || False
read "8.2" + 3.8
read "5" - 2
read "[1,2,3,4]" ++ [3]
# 型注釈(明示的な型指定)
read "5" :: Int
read "5" :: Float
(read "5" :: Float) * 4
read "[1,2,3,4]" :: [Int]
read "(3, 'a')" :: (Int, Char)
###ENum Bounded
['a'..'e']
[LT .. GT]
[3 .. 5]
succ 'B'
minBound :: Int
maxBound :: Char
maxBound :: Bool
minBound :: Bool
maxBound :: (Bool, Int, Char)
###Num Floating Integral
:t 20
20 :: Int
20 :: Integer
20 :: Float
20 :: Double
:t (*)