编程 haskell 下面这个程序是什么意思,运行时要怎么输入?
amplify2::String->Stringamplify2[]=[]amplify2(x:xs)=x:x:amplify2xs...
amplify2 :: String -> String
amplify2 [] = []
amplify2 (x : xs) = x : x : amplify2 xs 展开
amplify2 [] = []
amplify2 (x : xs) = x : x : amplify2 xs 展开
1个回答
展开全部
追问
amplify2 (x : xs) = x : x : amplify2 xs 这个句子要怎么理解。。
追答
首先string 其实是[Char],然后
x : xs这是个pattern match这个很简单吧。拿abc来说 amplify2 "abc" = "a":"a" : amplify2 "bc" = "a":"a" : "b":"b" : amplify2 "c" = "a":"a":"b":"b":"c":"c": amplify [] = "aabbcc"。
其实把递归展开就很清楚了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询