次世代言語議論スレ[Go Rust Scala Haskell]第5世代 [無断転載禁止]©2ch.net
■ このスレッドは過去ログ倉庫に格納されています
0084デフォルトの名無しさん
垢版 |
2017/06/25(日) 18:17:06.53ID:pYBZiqDJ
ライブラリ内部にも似た様なパターンを関数化して無駄に似た様な少し違うコードが少ない様にしてる。

Myfunc.hs自作ライブラリ
module Myfunc where

import Data.List
import Text.Printf

consnum::(Int,String) -> String
consnum (i,xs) = printf "%4d:%s" i xs

fline f = unlines.f.lines

fnumbering f = fline ((map consnum).(zip [1..]).f)

redstr::String -> String
redstr [] = []
redstr w = printf "\ESC[1m\ESC[31m%s\ESC[39m\ESC[0m" w

bluestr::String -> String
bluestr [] = []
bluestr w = printf "\ESC[34m%s\ESC[39m" w

grep w = fline (filter (isInfixOf w))
0085デフォルトの名無しさん
垢版 |
2017/06/25(日) 18:17:18.21ID:pYBZiqDJ
replace _ _ [] = []
replace [] _ cs = cs
replace w nw cs | w == xs = nw ++ replace w nw ys
where
(xs,ys) = splitAt (length w) cs
replace w nw (c:cs) = c:replace w nw cs

putfc (f,c) = printf "%s\n%s" f c

writefc (f,c) = writeFile f c

mfptn fs f ofs output = mapM readFile fs >>=
return.(zip ofs).map f >>=
mapM_ output

mfput f fs = mfptn fs f (map bluestr fs) putfc

mfwrite f fs = let tfs = map (++ ".temp") fs in
mfptn fs f tfs writefc >>
mfptn tfs id fs writefc
■ このスレッドは過去ログ倉庫に格納されています

ニューススポーツなんでも実況