I know that:
There is a distinction between the two in imperative languages like C, where operators are distinct from functions. However, is there any difference between the two in functional languages like Haskell where operators are functions too?
Is the only difference between the two that function inlining can be performed on selective parts of a program whereas partial evaluation is performed on the entire program (i.e. ∃
vs ∀
)?
What are the semantic differences between the two optimization techniques?
Full Functional Dependency equates to the normalization standard of Second Normal Form. Partial Functional Dependency does not equate to the normalization standard of Second Normal Form.
So, let’s first understand why inline functions are used and what is the purpose of inline function? When the program executes the function call instruction the CPU stores the memory address of the instruction following the function call, copies the arguments of the function on the stack and finally transfers control to the specified function.
Last thing to keep in mind that inline functions are the valuable feature of C++. An appropriate use of inline function can provide performance enhancement but if inline functions are used arbitrarily then they can’t provide better result. In other words don’t expect better performance of program.
* “Loss function” is the machine learning word for “ objective function ” — they’re the same thing.
There is a difference between
print(2*2)
as print(4)
. This needs by no means to be limited to operator expressions, as you seem to imply (e.g. print(sqrt(2.0)
)print(myfunc(2))
could be transformed into print(c)
where c
is the result of calling myfunc(2)
. It could then (at "specialisation time") call myfunc(2)
to determine c
. Of course, this will go badly wrong if myfunc
has side-effects, like wiping one's own hard disk instead of the program user's. Hence the compiler needs some sort of annotation or attribute to know when this is allowed/desired (e.g. C++11's constexpr) Inlining is an unrelated concept. Inlining a function call means replacing the call by the body of the called function. This body is not evaluated.
There is a distinction between the two in imperative languages like C, where operators are distinct from functions. However, is there any difference between the two in functional languages like Haskell where operators are functions too?
This distinctness (operators vs. functions) is purely syntactic, and is unrelated to the difference between inlining and partial evaluation:
Both function calls and expressions with operators can be inlined and compile-time evaluated in C. Compile-time evaluation is restricted to expressions over a fixed set of operators and functions (mostly operators, but that is historical accident)
Both concepts make sense and are distinct in Haskell.
ghc
has {-# INLINE f #-}
, where f
cannot be recursive, for obvious reasons,map f (map g xs
) into map (f . g) xs
). It can (but need not) do inlining as well. Template Haskell is another way to (explicitely) evaluate part of a program at compile-time.The answer to your title's question is thus: the difference between inlining and partial evaluation has nothing to do with the difference between functions and operators, and is much the same in functional languages as it is in C. Partial evaluation is probably more difficult in C because of side effects (cf the wiped hard disk above)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With