1
1 2
2 3
2 4
5
6
7
8
9
10
11
Haskell 12
13
Haskell 14
15
( ) 16
) 30 17
static 18
(IORef) 19
20
OK NG 21
Haskell (+) :: Num a => a -> a -> a sort :: Ord a => [a] -> [a] delete :: Eq a => a -> [a] -> [a] hgetline :: Handle -> IO String writefile :: FilePath -> String -> IO () writeioref :: IORef a -> a -> IO () IO IO 22
23
1) Ruby 24
1) Haskell 25
2) > split " foo bar baz " ["foo","bar","baz"] split :: String -> [String] split s s == "" = [] otherwise = w : split s where s = dropwhile isspace s (w, s ) = break isspace s 26
3) module Main where import Data.Char main :: IO () -- main = do cs <- getcontents -- print (wc cs) -- wc :: String -> Int -- wc xs = length (split xs) split :: String -> [String] split... 27
28
FILE * fopen(const char *, const char *); FILE * FILE * NULL NULL 29
30
NULL NULL, null, nil, None NULL 21 NULL 31
NULL 32
33
34
35
data Bool = False True data Either a b = Left a Right b data Maybe a = Nothing Just a 36
37
IO receive :: Socket -> IO String receive s = do cs <- recv s 4096 if cs == "" then throwio ConnectionClosedByPeer else return cs -- serv receive server :: Socket -> IO () server s = catch (serv s) logit where logit :: SomeException -> IO () logit e = print e 38
lookup lookup :: (Eq a) => a -> [(a,b)] -> Maybe b > lookup 5 [(2, a ),(5, b )] Just b > lookup 1 [(2, a ),(5, b )] Nothing lookup _key [] = Nothing lookup key ((x,y):xys) key == x = Just y otherwise = lookup key xys 39
Just a a Nothing getvalue :: Int -> [(Int, Char)] -> Char getvalue key db = case lookup key db of Just c -> c Nothing -> z 40
41
42
43
Haskell 44
Haskell 45
Haskell 100 % 46
Haskell 47
Haskell 48
Haskell 49
Haskell QuickCheck prop_doublesort :: [Int] -> Bool prop_doublesort xs = sort xs == sort (sort xs) > quickcheck prop_doublesort +++ OK, passed 100 tests. 50
7 1946 12 51
52
Haskeller 53
QuickCheck QuickCheck prop_model x xs = linearsearch x xs == binarysearch x xs ) 54
55
C union data Maybe a = Nothing Just a C struct data TLV a = TLV Tag Int a data Tree a = Leaf Node (Tree a) a (Tree a) 56
57
10,000 13 GC 58
* ) Wiki ============== ** \* [ URL] - 1 -- 2 -- 2-1 ++ 2 ++ 2 59
Wiki data Wiki = HR H Int HText P HText UOL Xlist type HText = [PText] data PText = Raw Char Escaped Char -- backslash Anchor Title URL type URL = String type Title = String data Xlist = Ulist [Xitem] Olist [Xitem] Empty data Xitem = Item HText Xlist 60
61
= NULL 62