Haskell 覚え書き

  • 等しくない 3 /= 5
  • 内包表記
ghci> [x * y | x <- [2,5,10], y <- [8, 10, 11], x * y > 50]
[55,80,100,110]

 

  • asパターン
firstLetter :: String -> String
firstLetter "" = "Empty String."
firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ [x]

 

  • let 式
ghci> let (a, b, c) = (1, 2, 3); d = 4 in (a + b + c) * d
24

 

ghci> map (\x -> x + 3) [1,6,3,2]
[4,9,6,5]