type (_, _) eq = Equal: ('a, 'a) eq(来源)有什么用?我已经refl在 Coq 中使用过,但还不需要像 OCaml 中那样的东西。
该类型已在即将发布的 OCaml Stdlib 版本中定义Base,并且.
我如何知道何时使用此类型,以及使用此类型的代码是什么样的?
基地文档说:
Type_equal 的目的是表示类型检查器不知道的类型相等性,否则可能是因为类型相等性取决于动态数据,或者可能是因为类型系统不够强大。
所以听起来我正在寻找类型相等性依赖于动态数据或类型系统不够强大的示例,而类型equal是有帮助的。
我发现使用了
equal具有相同定义的类型,Stdlib.camlinternalFormat但不理解它
更新上面的基本文档中的引用可能不是具体eq的,并且可能与Base.Type_equal.Idiuc 更相关。
我试图在这里解决问题,但我不知道为什么我的代码不起作用.任何帮助表示赞赏.编辑:编辑进行下面提到的修正,但在输出的第二行还有一个额外的"15"(粗体),我不明白它来自哪里.
我的输出是
18662658515 5552272 15
#include <stdlib.h>
#include <stdio.h>
int main(void){
int n;
int j;
scanf("%d\n", &n);
int i = 0;
char mystr[15];
for(;i<n;i++){
fgets(mystr,15,stdin);
for(j=0;j<15;j++){
if(isdigit(mystr[j])){
printf("%c", mystr[j]);
continue;
}
if ('A' <= mystr[j] && mystr[j] <= 'C')
printf("2");
if ('D' <= mystr[j] && mystr[j] <= 'F')
printf("3");
if ('G' <= mystr[j] && mystr[j] <= 'I')
printf("4");
if ('J' <= mystr[j] && mystr[j] <= 'L')
printf("5");
if ('M' <= mystr[j] && mystr[j] <= 'O')
printf("6"); …Run Code Online (Sandbox Code Playgroud) 我有下面的代码,它没有像我期望的那样工作......
current_frame = 15 # just for showcasing purposes
g_ch = 7
if (current_frame != int(row[0])) and (int(row[1]) != g_ch):
current_frame = int(row[0])
print "curious================================="
print current_frame
print row
print current_frame, " != ", int(row[0]), ", ", current_frame != int(row[0])
print "========================================"
Run Code Online (Sandbox Code Playgroud)
打印任何特定情况:
curious=================================
15
['15', '1', 'more data'] 15 != 15 , False
========================================
Run Code Online (Sandbox Code Playgroud)
这显然永远不会输入if语句,因为等式显示为false.为什么会这样?
编辑:我也试过这个!=而不是'不是',得到了相同的结果.
我正在为课程编写一个程序,我在其中分析输入的不同产品代码.这很简单,但我遇到了问题.如果用户输入"E"或"e",我试图结束循环.但是,它根本不会结束循环.这是在while语句的末尾,所以将循环设置为false应该结束它,它甚至不输出总数,所以我搞砸了一些东西.代码是字符串类型.
// Prompt the user for another company code or exit
System.out.print("Enter the company code or type 'e' to exit: ");
// Input the user's company code
code = scan.nextLine();
// Check to see if the user wants to exit
if (code == "e" || code == "E") {
// Output final statistics
System.out.print("Total valid codes: " + valid + "/n");
System.out.print("Total banned codes: " + banned);
// End the loop
loop = false;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
我有一个int数组的ArrayList,当我询问它是否包含指定的坐标时返回false.它确实包含我请求的坐标,因此它应该返回TRUE.
这是我的代码.
//debug code
for (int i = 0; i < Locations.size(); i++)
{
int[] TestLoc = Locations.get(i);
System.out.print(TestLoc[0] + " " + TestLoc[1] + " " + TestLoc[2] + " == " + Location[0] + " " + Location[1] + " " + Location[2] + "? - ");
if (Location == TestLoc)
{
System.out.println("TRUE");
}
else
{
System.out.println("FALSE");
}
}
//real code
if (Locations.contains(Location))
{
Locations.remove(Location);
}
else
{
System.out.println("FAIL");
}
Run Code Online (Sandbox Code Playgroud)
并输出,当列表包含4个坐标时请求坐标57,64,105.
56 64 105 == 57 …
今晚看到Python的一些意外行为.为什么以下打印出"不相等"?!
num = 1.00
num -= .95
nickel = .05
if nickel != num:
print 'not equal'
else:
print 'equal'
Run Code Online (Sandbox Code Playgroud) 如何才能实现以下目标:
$varnum = 4;
if( $varnum/4 - floor($varnum/4) !== 0){
echo 'foo';
}
Run Code Online (Sandbox Code Playgroud)
这与运行PHP 5.1.6的服务器上的'foo'相呼应.如果我改变操作员,==我得到相同的结果.
我不知道为什么,但可能是因为"=="是"等于"而"!=="是"不相同"?那怎么会让它们相同呢?我想在javaScript中我会"parseInt",但在PHP中没有这样的东西,对吧?
我注意到我的代码中存在一个问题IEnumerable似乎没有包含我想要的所有元素,这里是代码(它位于foreach中,这是我从中得到的_Lis):
IEnumerable<Pot> result = pots.Where(e => SignArray(e.PotVal) == _Lis.ToArray());
Console.WriteLine("Result count:" + result.Count());
Console.WriteLine(JObject.FromObject(new { test1 = SignArray(pots[0].PotVal) }));
Console.WriteLine(JObject.FromObject(new { test2 = _Lis.ToArray() }));
Run Code Online (Sandbox Code Playgroud)
结果:
Result count: 0
{
"test1": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0
]
}
{
"test2": [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0
]
}
Run Code Online (Sandbox Code Playgroud) 所以,当我编译下面编辑的代码时:
instance (Eq a) => PartOrd a where
[] == [] = True
(x:xs) == (y:ys) = x==y && xs==ys
_ == _ = False
xs /= ys = not (xs == ys)
Run Code Online (Sandbox Code Playgroud)
我明白了:
`==' is not a (visible) method of class 'PartOrd'
`/=' is not a (visible) method of class 'PartOrd'
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
我已经看过如何在Haskell中正确实例化类?有些澄清,但即使我无法解决它.
另外,当我使用=~for ==和/~for 等定制运算符时,它是否相同/=,因为我得到了同样的错误?
编辑:根据要求:
class Eq a => PartOrd a where …Run Code Online (Sandbox Code Playgroud) 我有一个output正在打印的双-0.000000
我有一个循环说:
if (output == 0) {
printf("Continuing to go STRAIGHT.\n");
}
else if (output > 0) {
printf("Turning LEFT.\n");
}
else if (output < 0) {
printf("Turning RIGHT.\n");
}
Run Code Online (Sandbox Code Playgroud)
这样可以保持打印第三个条件,说-0.000000小于0.为什么这样,我该如何解决这个问题呢?