|
|
|
|
|
by throwaway858
1266 days ago
|
|
That is not the definition of FP. There is no definition of what FP is that is agreed upon by everyone, but the key is the word "functional" in FP. This comes from a mathematical function, which is a mapping of input values to output values. You could write a definition of a function f(x) to be such that the value of f(x) is the result of the execution of some imperative-looking code (including loops that mutate variables). Mathematicians would be satisfied with such a definition and would confirm that f(x) is a function just as valid as any other. And so functional programmers should also accept such a function. In fact, Haskell has specific syntactical support ("do" notation) to allow you to write functions using imperative-looking code including mutations (the ST monad, or other State monads). |
|
Now I'm trying to wrap my head around how can I call a function which takes no arguments but which returns a value the user entered on the keyboard? How can I write a function which returns the current mouse-position on the screen, while still abiding by the functional principle of same result for same arguments always?
Can it be done? If not can we still call it "functional"?