简体   繁体   中英

beta reduction strategies in Haskell

This is my first time learning functional programming. I do understand how simple beta reduction works.

for example:

(\x->2*x)5

means that you substitute the xs with 5.

2*5=10

However, other examples confuse me

(\f->f(f 0))(\x->x+1)

We have learned about some evaluation strategies, head normal form and weak head normal forms.

from my notes, I understand that head normal form means no redex expression, while weak head normal form means there is a lambda abstraction.

This doesn't make any sense to me. Do one of the two apply to this last example? If so, what would be an example of the other strategy?

The term

(\f -> f (f 0)) (\x -> x+1)

is neither in head normal form nor in weak head normal form. This term is the application of a lambda (specifically, \\f -> f (f 0) ) to a term (specifically, \\x -> x+1 ), and so:

  1. There is a redex. Recall that a redex is defined as the application of a lambda to a term. Since there is a redex somewhere in the expression -- and in particular, at the very top level, in this case -- this is not in head normal form.
  2. The top level of the term is an application, not a lambda, so this is not in weak head normal form.

Neither "head normal form" nor "weak head normal form" is an evaluation strategy. Forms are adjectives which describe terms; evaluation strategies, in general, are verbs which describe how to change one term into another term.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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