小编Bli*_*lib的帖子

添加两个浮点数元组

我需要创建一个函数,将两个由浮点数组成的元组相加,并返回一个由两个浮点数组成的元组。

let add a b =
  fst a + fst b, snd a + snd b
Run Code Online (Sandbox Code Playgroud)

给我这个回报:

val add : int * int -> int * int -> int * int
Run Code Online (Sandbox Code Playgroud)

但如果我尝试:

let add (a:float) (b:float) =
  fst a + fst b, snd a + snd b
Run Code Online (Sandbox Code Playgroud)

我明白了:

This expression was expected to have type
    ''a * 'd'    
but here has type
    'float'    
Run Code Online (Sandbox Code Playgroud)

我该如何获得以下回报?

val add : float * float -> float * float -> float * float
Run Code Online (Sandbox Code Playgroud)

f# tuples function

1
推荐指数
1
解决办法
192
查看次数

标签 统计

f# ×1

function ×1

tuples ×1