Какова A-нормальная-форма?

Строка не может быть использована для выполнения операции.

Оператор switch - хороший способ решить проблему. Другой вариант - использовать карту:

var funcs = map[string]func(int, int) int{
    "+": func(a, b int) int { return a + b },
    "-": func(a, b int) int { return a - b },
    "*": func(a, b int) int { return a * b },
    "/": func(a, b int) int { return a / b },
}

fmt.Println(funcs["-"](6, 4))
fmt.Println(funcs["+"](6, 4))
fmt.Println(funcs["*"](6, 4))
11
задан unj2 6 May 2009 в 05:27
поделиться

2 ответа

See Administrative normal form.

In computer science, administrative normal form (abbreviated ANF) is a canonical form of programs, which was introduced by Flanagan et al 1993 to serve as an intermediate representation in functional compilers to make subsequent transformations to machine code more direct.

In ANF, all arguments to a function must be trivial. That is, evaluation of each argument must halt immediately.

Grammar

The following BNF grammar describes the pure λ-calculus modified to support the constraints of ANF:

EXP ::= VAL VAL
     |  let VAR = EXP in EXP
VAL ::= ? VAR . EXP
     |  VAR

Variants of ANF used in compilers or in research often allow constants, records, tuples, multiargument functions, primitive operations and conditional expressions as well.

Flanagan, Cormac; Sabry, Amr; Duba, Bruce F.;Felleisen, Matthias. "The Essence of Compiling with Continuations" likely is the definitive source.

Also found some notes on cs252r : Advanced Functional Programming.

6
ответ дан 3 December 2019 в 10:45
поделиться

In essence, a lambda term in administrative normal form can be read as a procedure for evaluating itself, since all arguments to applications must already be in 'evaluated' and thus the order in which arguments should be evaluated must necessarily be made explicit.

There's an interesting overview in this independently interesting paper on a strict intermediate language for compiling lazy functional languages. Section 3.1 et seq, and especially figure 7 which gives a small-step operational semantics for a strict language in administrative normal form.

2
ответ дан 3 December 2019 в 10:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: