将2个列表函数组合成1? [英] Combine 2 list functions into 1?

查看:162
本文介绍了将2个列表函数组合成1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何结合以下两个函数:

  replaceNth n newVal(x:xs)
| n == 0 = newVal:xs
|否则= x:replaceNth(n-1)newVal xs

replaceMthNth mnv arg = replaceNth m(replaceNth nv(arg !! m))arg
pre>

变成一个函数吗?

是否有可能?

  replacemn 

0(z:xs):xss)=(z:xs):xss
replacemn 0 nz((x:xs):xss)=
let(ys:yss)= replacemn 0 (x-ys):yss)
替换mnz(xs:xss)= xs:replacemn(m-1)nz xss


How would I combine the following 2 functions:

replaceNth n newVal (x:xs)
 | n == 0 = newVal:xs
 | otherwise = x:replaceNth (n-1) newVal xs

replaceMthNth m n v arg = replaceNth m (replaceNth n v (arg !! m)) arg

into a single function?

Is it possible?

解决方案

This is pretty hideous but it does the job:

replacemn 0 0 z ((x : xs) : xss) = (z : xs) : xss
replacemn 0 n z ((x : xs) : xss) =
  let (ys : yss) = replacemn 0 (n-1) z (xs : xss)
  in ((x : ys) : yss)
replacemn m n z (xs:xss) = xs : replacemn (m-1) n z xss

这篇关于将2个列表函数组合成1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆