gpt4 book ai didi

f# - 如何实现 DivideByInt

转载 作者:行者123 更新时间:2023-12-03 06:28:39 27 4
gpt4 key购买 nike

我正在尝试编写一个自定义 DivideByInt如下

type Pair = Pair of int * int with
static member DivideByInt pair int = pair


[<EntryPoint>]
let main argv =
LanguagePrimitives.DivideByInt (Pair(1,2)) 1
|> ignore
0

// compiler error: "FS0001: Method or object constructor 'DivideByInt' not found"

为什么编译器找不到 Pair.DivideByInt?

最佳答案

Pair.DivideByInt 必须采用元组作为输入

更正后的版本:

type Pair = Pair of int * int with
static member DivideByInt (pair, int) = pair

关于f# - 如何实现 DivideByInt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46443198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com