Open5
すごいHaskellたのしく学ぼう!を読んだメモ
repo
とりあえず、devcontainerで開発できるようにしてみた。
Image sizeが7.09GBになったけど、流石にでかすぎる気がする。CONTAINER REPOSITORY TAG IMAGE ID SIZE
learn-you-a-haskell-for-great-good-app-1 learn-you-a-haskell-for-great-good-app latest 69a8d8e661f3 7.09GB
リスト内包表記、めっちゃいいな
rightTriangles' = [ (a,b,c) | c <- [1..10], a <- [1..c], b <- [1..a], a^2 + b^2 == c^2, a+b+c == 24]
柔軟
src/Pipeline.hs
module Pipeline ((|>)) where
infixl 1 |>
(|>) a f = f a
ghci> print $ [1..] |> map (^2) |> take 50
[1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900,961,1024,1089,1156,1225,1296,1369,1444,1521,1600,1681,1764,1849,1936,2025,2116,2209,2304,2401,2500]
参考文献
レコード構文でデータ型を定義すると、2つの方法で値を作れる
data Car = Car
{ company :: String,
model :: String,
year :: Int
}
deriving (Show)
ghci
ghci> print Car {company = "Toyota", model = "Prius", year = 2017}
Car {company = "Toyota", model = "Prius", year = 2017}
ghci> print $ Car "Toyota" "Prius" 2017
Car {company = "Toyota", model = "Prius", year = 2017}