一段很有代数味道的代码
来自haskell 99题 http://haskell.org/haskellwiki/99_questions/21_to_28
--Insert an element at a given position into a list.
insertAt :: a -> [a] -> Int -> [a]
我本来的写法是
insertAt x xs pos = let ss = splitAt pos xs in fst ss ++ [x] ++ snd ss
insertAt x xs pos = let (ys,zs) = splitAt pos xs in ys ++ [x] ++ zs
我的思想仍然有命令式的味道,没想到还有这么"代数式"的写法。haskell里的“let"绝对就是数学里的“设“ ,太妙了