Programing in Haskell / Chapter.11

Programing in Haskell The countdown problem P.116-120
気がつけば6月、ちょっとサボってしまいました…

再帰のコードの書き方が今だにどういう発想でといていくのか理解できない。コードをみれば、どういう風に動いているかは追跡ができるんだけど…実際に自分で考えるとなると難しいですなー

subs :: [a] -> [[a]]
subs [] = [[]]
subs (x:xs) = yss ++ map (x:) yss
              where yss = subs xs

interleave :: a -> [a] -> [[a]]
interleave x []     = [[x]]
interleave x (y:ys) = (x:y:ys):map (y:) (interleave x ys)

perms :: [a] -> [[a]]
perms []     = [[]]
perms (x:xs) = concat (map (interleave x) (perms xs))

-- P.119のeがなかなか書くのがめんどくさいので定義しておきます
e = (App Mul (App Add (Val 1) (Val 50)) (App Sub (Val 25)  (Val 10)))

ちょっと更新頻度がんばりたいです。