haskell - Why is a built-in function applied to too few arguments considered to be in weak head normal form? -


the haskell definition says:

an expression in weak head normal form (whnf), if either:

  • a constructor (eventually applied arguments) true, (square 42) or (:) 1
  • a built-in function applied few arguments (perhaps none) (+) 2 or sqrt.
  • or lambda abstraction \x -> expression.

why built-in functions receive special treatment? according lambda calculus, there no difference between partially applied function , other function, because @ end have 1 argument functions.

a normal function applied argument, following:

(\x y -> x + 1 : y) 1 

can reduced, give:

\y -> 1 + 1 : y 

in first expression, "outermost" thing application, not in whnf. in second, outermost thing lambda abstraction, in whnf (even though more reductions inside function body).

now lets consider application of built-in (primitive) function:

(+) 1 

because built-in, there's no function body in can substitute 1 first parameter. evaluator "just knows" how evaluate "saturated" applications of (+), (+) 1 2. there's nothing can done partially applied built-in; can produce data structure describing "apply (+) 1 , wait 1 more argument", that's thing we're trying reduce is. nothing.

built-ins special because they're not defined lambda calculus expressions, reduction process can't "see inside" definition. thus, unlike normal functions applications, built-in function applications have "reduced" accumulating arguments until "saturated" (in case reduction whnf running whatever magic implementation of built-in is). unsaturated built-in applications cannot reduced further, , in whnf.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -