What does?is it?

what is it和what is this的区别_百度知道
what is it和what is this的区别
我有更好的答案
what is it 它是什么what is this 这是什么
it表特指,表示一个,而this则表泛指,表示一种、一类.一般情况下不做区分.希望采纳
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。当前位置:
该科目暂无子分类
类型筛选:
精品/普通:
地区筛选:
星级筛选:
21世纪教育
中小学教师帮Anyone who has taken even a cursory glance at the vast menagerie of programming languages should have at least heard the phrase “Hindley-Milner”.& F#, one of the most promising languages ever to emerge from the forbidding depths of Microsoft Research, makes use of this mysterious algorithm, as do Haskell, OCaml and ML before it.& There is even some research being undertaken to find a way to apply the power of HM to optimize dynamic languages like Ruby, JavaScript and Clojure.
However, despite widespread application of the idea, I have yet to see a decent layman’s-explanation for what the heck everyone is talking about.& How does the magic actually work?& Can you always trust the algorithm to infer the right types?& Further, why is Hindley-Milner is better than (say) Java?& So, while those of you who actually know what HM is are busy recovering from your recent aneurysm, the rest of us are going to try to figure this out.
Ground Zero
Functionally speaking, Hindley-Milner (or “Damas-Milner”) is an algorithm for inferring value types based on use.& It literally formalizes the intuition that a type can be deduced by the functionality it supports.& Consider the following bit of psuedo-Scala (not a flying toy):
def foo(s: String) = s.length
// note: no explicit types
def bar(x, y) = foo(x) + y
Just looking at the definition of bar, we can easily see that its type must be (String, Int)=>Int.& As humans, this is an easy thing for us to intuit.& We simply look at the body of the function and see the two uses of the x and y parameters.& x is being passed to foo, which expects a String.& Therefore, x must be of type String for this code to compile.& Furthermore, foo will return a value of type Int.& The + method on class Int expects an Int thus, y must be of type Int.& Finally, we know that + returns a new value of type Int, so there we have the return type of bar.
This process is almost exactly what Hindley-Milner does: it looks through the body of a function and computes a constraint set based on how each value is used.& This is what we were doing when we observed that foo expects a parameter of type String.& Once it has the constraint set, the algorithm completes the type reconstruction by unifying the constraints.& If the expression is well-typed, the constraints will yield an unambiguous type at the end of the line.& If the expression is not well-typed, then one (or more) constraints will be contradictory or merely unsatisfiable given the available types.
Informal Algorithm
The easiest way to see how this process works is to walk it through ourselves.& The first phase is to derive the constraint set.& We start by assigning each value (x and y) a fresh type (meaning “non-existent”).& If we were to annotate bar with these type variables, it would look something like this:
def bar(x: X, y: Y) = foo(x) + y
The type names are not significant, the important restriction is that they do not collide with any “real” type.& Their purpose is to allow the algorithm to unambiguously reference the yet-unknown type of each value.& Without this, the constraint set cannot be constructed.
Next, we drill down into the body of the function, looking specifically for operations which impose some sort of type constraint.& This is a depth-first traversal of the AST, which means that we look at operations with higher-precedence first.& Technically, it doesn’t matte I just find it easier to think about the process in this way.& The first operation we come across is the dispatch to the foo method.& We know that foo is of type String=>Int, and this allows us to add the following constraint to our set:
X& & String
The next operation we see is +, involving the y value.& Scala treats all operators as method dispatch, so this expression actually means “foo(x).+(y).& We already know that foo(x) is an expression of type Int (from the type of foo), so we know that + is defined as a method on class Int with type Int=>Int (I’m actually being a bit hand-wavy here with regards to what we do and do not know, but that’s an unfortunate consequence of Scala’s object-oriented nature).& This allows us to add another constraint to our set, resulting in the following:
X& & String
The final phase of the type reconstruction is to unify all of these constraints to come up with real types to substitute for the X and Y type variables.& Unification is literally the process of looking at each of the constraints and trying to find a single type which satisfies them all.& Imagine I gave you the following facts:
Daniel is tall
Chris is tall
Daniel is red
Chris is blue
Now, consider the following constraints:
Person1 is tall
Person1 is red
Hmm, who do you suppose Person1 might be?& This process of combining a constraint set with some given facts can be mathematically formalized in the guise of unification.& In the case of type reconstruction, just substitute “types” for “facts” and you’re golden.
In our case, the unification of our set of type constraints is fairly trivial.& We have exactly one constraint per value (x and y), and both of these constraints map to concrete types.& All we have to do is substitute “String” for “X” and “Int” for “Y” and we’re done.
To really see the power of unification, we need to look at a slightly more complex example.& Consider the following function:
def baz(a, b) = a(b) :: b
This snippet defines a function, baz, which takes a function and some other parameter, invoking this function passing the second parameter and then “cons-ing” the result onto the second parameter itself.& We can easily derive a constraint set for this function.& As before, we start by coming up with type variables for each value.& Note that in this case, we not only annotate the parameters but also the return type.& I sort of skipped over this part in the earlier example since it only sufficed to make things more verbose.& Technically, this type is always inferred in this way.
def baz(a: X, b: Y): Z = a(b) :: b
The first constraint we should derive is that a must be a function which takes a value of type Y and returns some fresh type Y’ (pronounced like “why prime“).& Further, we know that :: is a function on class List[A] which takes a new element A and produces a new List[A].& Thus, we know that Y and Z must both be List[Y'].& Formalized in a constraint set, the result is as follows:
X& & (Y=>Y’ )
Y& & List[Y' ]
Z& & List[Y' ]
Now the unification is not so trivial.& Critically, the X variable depends upon Y, which means that our unification will require at least one step:
X& & ( List[Y' ]=>Y’ )
Y& & List[Y' ]
Z& & List[Y' ]
This is the same constraint set as before, except that we have substituted the known mapping for Y into the mapping for X.& This substitution allows us to eliminate X, Y and Z from our inferred types, resulting in the following typing for the baz function:
def baz(a: List[Y']=&Y', b: List[Y']): List[Y'] = a(b) :: b
Of course, this still isn’t valid.& Even assuming that Y' were valid Scala syntax, the type checker would complain that no such type can be found.& This situation actually arises surprisingly often when working with Hindley-Milner type reconstruction.& Somehow, at the end of all the constraint inference and unification, we have a type variable “left over” for which there are no known constraints.
The solution is to treat this unconstrained variable as a type parameter.& After all, if the parameter has no constraints, then we can just as easily substitute any type, including a generic.& Thus, the final revision of the baz function adds an unconstrained type parameter “A” and substitutes it for all instances of Y’ in the inferred types:
def baz[A](a: List[A]=&A, b: List[A]): List[A] = a(b) :: b
Conclusion
…and that’s all there is to it!& Hindley-Milner is really no more complicated than all of that.& One can easily imagine how such an algorithm could be used to perform far more complicated reconstructions than the trivial examples that we have shown.
Hopefully this article has given you a little more insight into how Hindley-Milner type reconstruction works under the surface.& This variety of type inference can be of immense benefit, reducing the amount of syntax required for type safety down to the barest minimum.& Our “bar” example actually started with (coincidentally) Ruby syntax and showed that it still had all the information we needed to verify type-safety.& Just a bit of information you might want to keep around for the next time someone suggests that all statically typed languages are overly-verbose.
Post a CommentWhat Day Is It?(模拟)
#include&cstdio&
#include&cstring&
#include&string&
#include&algorithm&
#include&iostream&
int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int judge(int year)
if(year&=1752)
if(year%4==0)
if(year%4==0&&year%100)
else if(year%4==0&&year%100==0&&year%400==0)
int judge2(int month,int day,int year)
if(month&12||(month!=2&&months[month]&day)||(month==2&&!judge(year)&&months[month]&day)||(month==2&&judge(year)&&months[month]+1&day)||(1752==year&&month==9&&(day&2&&day&14)))
void printmonth(int a)
printf("January");
printf("February");
printf("March");
printf("April");
printf("May");
printf("June");
printf("July");
printf("August");
printf("September");
printf("October");
printf("November");
printf("December");
void printday(int c)
printf("Monday\n");
printf("Tuesday\n");
printf("Wednesday\n");
printf("Thursday\n");
printf("Friday\n");
printf("Saturday\n");
printf("Sunday\n");
int main()
int year,month,day,t,flag,day2,i,j,k;
while(scanf("%d %d %d",&month,&day,&year))
if(month==0||year==0||day==0)
if(judge2(month,day,year)==0)
printf("%d/%d/%d is an invalid date.\n",month,day,year);
for(i=1;i&i++)
if(judge(i)==1)
day2+=366;
day2+=365;
for(i=1;i&i++)
day2+=months[i];
if(judge(year)&&month&2)
day2=day2+day-1;
if(year&1752||(year==1752&&month&9)||(year==1752&&month==9&&day&=14))
day2=day2%7;
printmonth(month);
printf(" %d, %d is a ",day,t);
printday(day2);
没有更多推荐了,
不良信息举报
举报内容:
What Day Is It?(模拟)
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!}

我要回帖

更多关于 what is it的发音 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信