当我在ghci中输入<body>
<form onlogin="return checkForm(this);">
<p><input type="text" name="username" placeholder="Enter Username"></p>
<p><input type="password" name="pwd1" placeholder="Enter Password"></p>
<p><button type="login"placeholder="Login"></p>
<p> <a href="#">Forgot your password?</a></p>
</form>
<script type="text/javascript">
function checkForm(form)
{
if(form.username.value == "") {
alert("Error: Username cannot be blank!");
form.username.focus();
return false;
}
re = /^\w+$/;
if(!re.test(form.username.value)) {
alert("Error: Username must contain only letters, numbers and underscores!");
form.username.focus();
return false;
}
if(form.pwd1.value != "") {
if(form.pwd1.value.length < 6) {
alert("Error: Password must contain at least six characters!");
form.pwd1.focus();
return false;
}
if(form.pwd1.value == form.username.value) {
alert("Error: Password must be different from Username!");
form.pwd1.focus();
return false;
}
re = /[0-9]/;
if(!re.test(form.pwd1.value)) {
alert("Error: password must contain at least one number (0-9)!");
form.pwd1.focus();
return false;
}
re = /[a-z]/;
if(!re.test(form.pwd1.value)) {
alert("Error: password must contain at least one lowercase letter (a-z)!");
form.pwd1.focus();
return false;
}
re = /[A-Z]/;
if(!re.test(form.pwd1.value)) {
alert("Error: password must contain at least one uppercase letter (A-Z)!");
form.pwd1.focus();
return false;
}
} else {
alert("Error: Please check that you've entered and confirmed your password!");
form.pwd1.focus();
return false;
}
alert("You entered a valid password: " + form.pwd1.value);
return true;
}
时,我得到了
:t 4
我理解为什么Prelude> :t 4
4 :: Num t => t
不仅仅是一个整数或一个整数而且它是自下而上的,但我不明白为什么4
没有显示为4
或更多纠正这样的事情:
Ord t => t
因为4 :: (Ord t || Num t) => t
既是4
又是Ord
,但Num
和Ord
没有联系......
那么Num
为什么只输出:t 4
?
答案 0 :(得分:9)
并非所有包含Num
实例的类型也都有Ord
的实例,并且您只需要fromInteger
的{{1}}部分来获得Haskell所具有的重载数字文字。例如,Data.Complex
中的Num
有Complex
个实例,但没有Num
。在这种情况下,Ord
不 4
。
Ord
正如@Lee评论的那样,这是report中概述的行为。