简体   繁体   English

弱头正常形式和正常形式

[英]Weak head normal form and normal form

I have question about weak head normal form and normal form. 我对弱头正常形态和正常形态有疑问。

Weak head normal form means, the expression will only evaluate as far as necessary to reach to a data constructor. 弱头范式意味着,表达式只会在达到数据构造函数所需的范围内求值。

Normal form means, the expression will be fully evaluated. 范式表示表达式将被完全求值。

Now, I have following expression: 现在,我有以下表达:

\x -> x * 10

Why the expression above is in normal form? 为什么上面的表达式是正常形式?

"Papu" ++ "chon"

Why the expression above is in neither WHNF nor NF? 为什么以上表达既不在WHNF中,又不在NF中?

WHNF evaluates far enough to reach a data constructor or lambda function . WHNF进行评估的程度足以达到数据构造函数或lambda函数

If you have a lambda function that hasn't been called with an argument, you cannot evaluate it any further anyway. 如果您有未使用参数调用的lambda函数,则无论如何都无法对其进行评估。 So a lambda function is in WHNF, and indeed NF, since there is nothing to evaluate further. 因此,lambda函数存在于WHNF中,实际上在NF中,因为没有进一步评估的方法。 Now, if you call the lambda function with an argument, we can evaluate what the result might be. 现在,如果您使用参数调用 lambda函数,我们可以评估结果可能是什么。 But the lambda function on its own? 但是lambda函数本身吗? Nothing further to be done. 没什么可做的了。

Your first expression is a lambda function with no arguments. 您的第一个表达式是不带参数的lambda函数。 It is therefor in normal form. 因此它是正常形式的。

Your second expression is neither a data constructor nor a lambda, hence is not in any normal form. 您的第二个表达式既不是数据构造函数也不是lambda,因此不是任何正常形式。 Now, if you evaluate it for one step, you obtain 现在,如果您对它进行一步评估,您将获得

'P' : ("apu" ++ "chon")

Which (although the syntax doesn't look like it) begins with a data constructor (namely (:) ), and hence is in WHNF, but not NF (since it still contains the unevaluated (++) subexpression). 其中(虽然语法看起来并不像它)与数据构造开始(即(:) ),因此 WHNF,但不是 NF(因为它仍包含未计算(++)子表达式)。

Perhaps it's easier if we get rid on the infix syntax: 如果我们摆脱了infix语法,也许会更容易:

(++) "Papu" "chon"

vs

(:) 'P' ( (++) "apu" "chon" )
 \\x -> x * 10 

Why the expression above is in normal form? 为什么上面的表达式是正常形式?

Because, you can't simplify it. 因为,您无法简化它。


 "Papu" ++ "chon" 

Why the expression above is in neither WHNF nor NF? 为什么以上表达既不在WHNF中,又不在NF中?

First of all, if some expression in NF - that means it's in WHNF. 首先,如果NF中有某些表达-这意味着它在WHNF中。 NF it's more restricted version of WHNF. NF是WHNF的受限版本。

So, We can restructure your question. 因此,我们可以调整您的问题。 Why the expression above isn't in WHNF? 为什么上面的表达式不在WHNF中?

Simple answer is: We can simplify it to "Papuchon" . 简单的答案是:我们可以将其简化为"Papuchon"


If you want to know what difference between WHNF and NF, you can read, for example, this . 如果您想了解WHNF和NF之间的区别,可以阅读this

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM