SML functional programming higher order function?

与世无争的帅哥 提交于 2019-12-13 09:49:49

问题


I need to implement a function

 ziprev : 'a list -> 'b list -> ('a * 'b) list
 - ziprev [1,2,3,4] [10,20,30,40];
 val it = [(1,40),(2,30),(3,20),(4,10)] : (int * int) list

Using a function that I already created:

- zipW (fn (x, y) => x + y) [1,2,3,4] [10,20,30,40];
val it = [11,22,33,44] : int list

and the List.rev from the library. I have no idea how to do a function with two libraries. Any suggestions?


回答1:


Hint 1:

Compare the result of your ziprev with

List.zip [1,2,3,4] [10,20,30,40]

You should see a fairly obvious pattern.

Hint 2:

List.rev reverses a list.

Hint 3:

Can you use zipW to implement List.zip?
That is, if you want to say

normalzip xs ys = zipW something xs ys

what would something be?



来源:https://stackoverflow.com/questions/14589802/sml-functional-programming-higher-order-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!