- 関数型プログラミング言語Haskell Part28 [転載禁止]©2ch.net
246 :デフォルトの名無しさん[sage]:2016/04/02(土) 00:30:07.50 ID:Ev1W2wgk - >>244
split = split' [] "" split' acc buff "" = reverse $ reverse buff :acc split' acc buff (x:xs) | x == '?' = split' (reverse buff :acc) "" xs | otherwise = split' acc (x:buff) xs main = print $ split "213?46464?698" こんなもんだろ。既に区切った語のリストをaccに蓄積して 今読んでる途中の語はbuffに蓄積してやる(適宜reverseで順番を直す)
|
- 関数型プログラミング言語Haskell Part28 [転載禁止]©2ch.net
247 :デフォルトの名無しさん[sage]:2016/04/02(土) 00:45:02.18 ID:Ev1W2wgk - 素朴な再帰ならこうだな
split "" = [""] split (x:xs) | x == '?' = "" :split xs | otherwise = (x:hd):tl where (hd:tl) = split xs main = print $ split "213?46464?698" 蓄積引数を使って末尾再帰にするか こちらにするかはまあ好きにしたらいいと思う。
|
- 関数型プログラミング言語Haskell Part28 [転載禁止]©2ch.net
253 :デフォルトの名無しさん[sage]:2016/04/02(土) 14:20:52.45 ID:Ev1W2wgk - >>249
無限リスト上で末尾再帰したらそりゃ戻ってこないよw
|