gpt4 book ai didi

casting - OCaml:将 bool 转换/转换为 int

转载 作者:行者123 更新时间:2023-12-05 08:23:52 25 4
gpt4 key购买 nike

如何将 ocaml bool 值转换为整数? (没有 int_of_bool 函数。)

最佳答案

这是一种可能的实现方式:

let int_of_bool b = if b then 1 else 0

库 OCaml Batteries Included 在其 BatBool module 中有一个函数 to_int .

关于casting - OCaml:将 bool 转换/转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32421369/

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