- 追加された行はこの色です。
- 削除された行はこの色です。
[[ネタ記録庫]]
* StateT [#x763ddb2]
これは、permutationを返す関数:
permutation' :: [[Int]] -> Int -> [Int] -> [[Int]]
permutation' result 0 _ = result
permutation' result n cand =
do a <- cand
permutation' (map (a:) result) (n-1) [x|x<-cand,x/=a]
使い方
permutation' [[]] [1,2,3] 2
のように使う。
これをStateTを使ってわざと分かりにくくしてみる:
permutation :: [[Int]] -> Int -> StateT [Int] [] [[Int]]
permutation result 0 = return result
permutation result n =
do cand <- get
a <- lift cand
put [x|x<-cand,x/=a]
permutation (map (a:) result) (n-1)
これは
runStateT (permutation [[]] 2) [1,2,3]
のように使う。
- Thx. 勉強になります。 -- [[げんま]] &new{2007-04-24 (火) 12:45:05};
#comment
*HaskellでWIKI [#x4eef27a]
書いてみました。いまのところ日本語は使えません。
http://icecs.ice.nuie.nagoya-u.ac.jp/~h043078b/wiki.cgi