3 ms·
Purity is, informally speaking, "same output for same input". If you start out with the same database and feed the same input in the same time intervals to a FR
by pka 13y ago
Purity is, informally speaking, "same output for same input". If you start out with the same database and feed the same input in the same time intervals to a FRP program, the resulting database will always be the same, (i.e. if you view the database as a value).
In the real world, a database is of course stateful, but then again so are CPU registers. There's no fundamental difference.
- sp332 13y agoThat's not true. Functional purity means there are no side-effects. What you're describing is simple determinism.
- pka 13y agoA function like sqrt :: Double -> Double is pure. Still, when evaluated on a CPU somewhere a register or a memory location gets mutated, i.e. it produces a side effect. In that sense nothing would be pure. So if sqrt is pure, why is addUser :: User -> DB -> DB impure?
- sp332 13y agoIf you make a new database and return it without modifying the original, it's pure.
- pka 13y agoDatomic is an example of a database-as-a-value - http://www.infoq.com/presentations/Datomic-Database-Value http://www.infoq.com/presentations/Datomic-Database-Value
- deleted 13y ago[deleted]
- colanderman 13y agoYes, that function is pure. Purity is a property of functions. The system formed by that function being repeatedly applied to the value of DB over time is stateful. Statefulness is a property of systems. Also, forget about CPU-level stuff. That's a straw man and is irrelevant to the discussion; everyone in this thread is talking about the holistic (i.e. system-level) definition of state, as that is what FRP manages. Beside, the mathematical mechanism by which a stateful system (the CPU) can be considered to be holistically stateless (a purely functional program) is the exact same mechanism by which a stateless system (a functional description of a state machine) can be considered to be holistically stateful -- that is by the definition I gave above and will repeat below. Again: the definition of a stateful system is one whose observable behavior is dependent on historical inputs. You are conflating this well-accepted notion of state with the independent concepts of referential transparency, (non)locality, and (non)determinism.
- colanderman 13y agoIf you start out with the same database and feed the same input in the same time intervals to a FRP program, the resulting database will always be the same, (i.e. if you view the database as a value). You realize that's true of, like, every digital computing system ever, right?