弱头正常形式和正常形式

弱头正常形式和正常形式

本文介绍了弱头正常形式和正常形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对弱头正常形态和正常形态有疑问.

I have question about weak head normal form and normal form.

弱头范式意味着该表达式只会在达到数据构造函数所需的范围内求值.

正常形式表示,表达式将被完全求值.

现在,我有以下表达:

\x -> x * 10

为什么上面的表达式是正常形式?

Why the expression above is in normal form?

"Papu" ++ "chon"

为什么上面的表达式既不在WHNF中又不在NF中?

Why the expression above is in neither WHNF nor NF?

推荐答案

WHNF计算得出的结果足以达到数据构造函数或lambda函数.

WHNF evaluates far enough to reach a data constructor or lambda function.

如果您有未使用参数调用的lambda函数,则无论如何都无法对其进行评估.因此,lambda函数存在于WHNF中,实际上在NF中,因为没有进一步评估的方法.现在,如果您调用带有参数的lambda函数,我们可以评估结果可能是什么.但是lambda函数本身吗?没什么可做的了.

If you have a lambda function that hasn't been called with an argument, you cannot evaluate it any further anyway. So a lambda function is in WHNF, and indeed NF, since there is nothing to evaluate further. Now, if you call the lambda function with an argument, we can evaluate what the result might be. But the lambda function on its own? Nothing further to be done.

您的第一个表达式是不带参数的lambda函数.因此是正常形式.

Your first expression is a lambda function with no arguments. It is therefor in normal form.

您的第二个表达式既不是数据构造函数也不是lambda,因此不是任何正常形式.现在,如果您对它进行一步评估,您将获得

Your second expression is neither a data constructor nor a lambda, hence is not in any normal form. Now, if you evaluate it for one step, you obtain

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

(虽然语法看起来不像)以数据构造函数(即(:))开头,因此在WHNF中是,但是不是 NF(因为它仍然包含未评估的(++)子表达式).

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).

如果我们摆脱了infix语法,也许会更容易:

Perhaps it's easier if we get rid on the infix syntax:

(++) "Papu" "chon"

vs

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

这篇关于弱头正常形式和正常形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:02