在函数式编程中,是否有接受 x 并返回元组 (x, x) 的函数的名称?
In functional programming, is there a name for a function that takes an x and gives back a tuple (x, x)?
我想知道在 ML 系列语言或更普遍的函数式编程语言中是否有一个常用术语来表示将值转换为 tuple-2 的函数?
let toTuple2 x = (x, x)
在诸如 Forth 之类的 stack-based programming languages 中,dup
是一个核心运算符,它确实复制了栈顶元素(虽然不完全是一个元组)。
在Haskell,various packages provide this function under names like dup
, dupe
or double
. Notice that two-tuples are also a core element of arrows, and dup = id &&& id
.
我没有找到任何特定于 ML 的内容。
我不知道那个特定函数的名称。
但是,该函数可以看作是更一般函数的特例:
let applyCtorToXX c x = c x x
确实,您可以验证 toTuple2
等同于 applyCtorToXX (,)
。
在组合逻辑中,或者至少在To Mock a Mockingbird, such a function is named a "Warbler”中是如何表示的,符号W
用于它(即Wxy = xyy
是在Wxy = xyy
中使用的定义书)。
从这个角度来看,你的toTuple2
就是W (,)
,就是莺莺对二元组构造函数的应用
我想知道在 ML 系列语言或更普遍的函数式编程语言中是否有一个常用术语来表示将值转换为 tuple-2 的函数?
let toTuple2 x = (x, x)
在诸如 Forth 之类的 stack-based programming languages 中,dup
是一个核心运算符,它确实复制了栈顶元素(虽然不完全是一个元组)。
在Haskell,various packages provide this function under names like dup
, dupe
or double
. Notice that two-tuples are also a core element of arrows, and dup = id &&& id
.
我没有找到任何特定于 ML 的内容。
我不知道那个特定函数的名称。
但是,该函数可以看作是更一般函数的特例:
let applyCtorToXX c x = c x x
确实,您可以验证 toTuple2
等同于 applyCtorToXX (,)
。
在组合逻辑中,或者至少在To Mock a Mockingbird, such a function is named a "Warbler”中是如何表示的,符号W
用于它(即Wxy = xyy
是在Wxy = xyy
中使用的定义书)。
从这个角度来看,你的toTuple2
就是W (,)
,就是莺莺对二元组构造函数的应用