简体   繁体   English

Clean 中的模函数

[英]Modulo function in Clean

Is there a predefined way to compute the modulo of two integers in Clean?是否有预定义的方法来计算 Clean 中两个整数的模数?

StdOverloaded defines the (mod) typeclass, but StdInt does not contain an instance of it, and StdEnv does not either anywhere else. StdOverloaded 定义了 (mod) 类型类,但 StdInt 不包含它的实例,StdEnv 也不包含其他任何地方。 I have seen a language overview about Clean version 2.0, which mentions StdInt's mod instance, but in 2.4, it is definitely missing.我看过关于 Clean 2.0 版的语言概述,其中提到了 StdInt 的 mod 实例,但在 2.4 中,它肯定是缺失的。

StdInt delivers another alternative: it's called rem. StdInt 提供了另一种选择:它称为 rem。 Works just like the old fashioned mod function, but also works fine with signed integers.就像老式的 mod 函数一样工作,但也适用于有符号整数。

10 rem 7 // 3

10 rem -7 // 3

-10 rem 7 // -3

-10 rem -7 //-3

在最新的稳定版本 (Clean 3.0) 中,只需导入 StdEnv 实例就可以使用“rem”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这是 JavaScript function,采用可变参考参数,纯 function 吗? - Is this JavaScript function, taking a mutable reference argument, a pure function? 如何测试返回函数的函数? - How to test a function that returns functions? 这个功能纯吗? (随机计算,确定性结果) - Is this function pure? (Random computation, deterministic result) 这可以被认为是一个纯函数(函数式编程)吗? - Can this be considered a pure function (functional programming)? 将Haskell函数转换为无点表示 - Transforming a Haskell function to a point free representaion 如何在不更新对函数的所有调用的情况下向纯函数添加新参数? - How do you add a new argument to a pure function without having to update all calls to the function? 函数式编程:当输入需要突变时,如何将不纯的 function 转换为纯 function - Functional Programming: How to convert an impure function to a pure function when the input needs to be mutated “错误”功能的存在如何影响Haskell的纯度? - How does the presence of the “error” function bear on the purity of Haskell? 如何使这个函数纯 - How to make this function pure 有状态功能管道 - Stateful function pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM