Search code examples
functional-programmingreferential-transparency

understanding referential transparency


Generally, I have a headache because something is wrong with my reasoning:

  1. For 1 set of arguments, referential transparent function will always return 1 set of output values.

  2. that means that such function could be represented as a truth table (a table where 1 set of output parameters is specified for 1 set of arguments).

  3. that makes the logic behind such functions is combinational (as opposed to sequential)

  4. that means that with pure functional language (that has only rt functions) it is possible to describe only combinational logic.

The last statement is derived from this reasoning, but it's obviously false; that means there is an error in reasoning. [question: where is error in this reasoning?]

UPD2. You, guys, are saying lots of interesting stuff, but not answering my question. I defined it more explicitly now. Sorry for messing up with question definition!


Solution

  • The error in Your reasoning is the following:
    "that means that such function could be represented as a truth table".

    You conclude that from a functional language's property of referential transparency. So far the conclusion would sound plausible, but You oversee that a function is able to accept collections as input and process them in contrast to the fixed inputs of a logic gate.

    Therefore a function does not equal a logic gate but rather a construction plan of such a logic gate depending on the actual (at runtime determined) input!

    To comment on Your comment: Functional languages can - although stateless - implement a state machine by constructing the states from scratch each time they are being accessed.