SML函数式编程高阶函数? [英] SML functional programming higher order function?

查看:444
本文介绍了SML函数式编程高阶函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个函数

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

p

使用我已经创建的函数:

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

和List.rev来自库。
我不知道如何做两个库的函数。任何建议?

解决方案

提示1:

比较您的 ziprev

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

您应该看到一个相当明显的模式。



提示2:

List.rev 反转列表。



提示3:



您可以使用 zipW 来实现 List.zip ? >
也就是说,如果你想说的话

  normalzip xs ys = zipW something xs ys 

什么是某物是?


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?

解决方案

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?

这篇关于SML函数式编程高阶函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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