久しぶりにhaskellを触ったので、その際に調べたtips的な処理についてメモ
リストのslice
https://stackoverflow.com/questions/4597820/does-haskell-have-list-slices-i-e-python
slice :: Int -> Int -> [a] -> [a] slice from to xs = take (to - from + 1) (drop from xs)
リストから最大値を持つindexを取得(argmax)
import Data.List import Data.Ord maximumBy (comparing fst) (zip xs [0..])
Intリストの累積和
https://stackoverflow.com/questions/4732282/calculating-list-cumulative-sum-in-haskell
scanl1 (+) [1,2,3]
コマンドライン引数
https://hackage.haskell.org/package/base-4.14.0.0/docs/System-Console-GetOpt.html#g:4
簡単なスクリプトの引数を設定するのならbuiltinのGetOptでこのようにやるだけで十分