3 ms·
What? No, that isn’t true at all. State machines come before the FP/IP divide even existed. State machines are also intrinsically stateful, that should be obvi
by seanmcdirmid 9y ago
What? No, that isn’t true at all. State machines come before the FP/IP divide even existed.
State machines are also intrinsically stateful, that should be obvious.
- tytytytytytytyt 9y ago> State machines are also intrinsically stateful, that should be obvious. So are lots of data types, but those are still useful in FP.
- seanmcdirmid 9y agoYes, that should be obvious also. State machines have no strong relationship with FP. I'm not sure where this claim even comes from!
- noblethrasher 9y agoIn 's4vi0r’s defense, “FP” usually means ML-style FP, which does happen to be pretty biased towards creating stack-based FSMs since it has literal syntax for stacks (list literals), states (discriminated unions + tuples), and transitions (pattern matching).
- coldtea 9y ago>“FP” usually means ML-style FP Only after sometime around 2010. Before that it was mostly Lisp and Scheme. Sometime around then, the trend around Haskell, purity, and co overtook them as what people mean when they talk about FP.
- throwaway010317 9y agoThis comment reminds me of something I read recently on Yaron Minsky's twitter: "An odd habit of functional programmers: when confronted with a nice, but clearly imperative way of structuring a program, they will often declare that this technique is in fact functional." (https://twitter.com/yminsky/status/950883335324225541 https://twitter.com/yminsky/status/950883335324225541) and then "Case in point: structuring a program as an imperative, deterministic state machine, where the state is determined fully by the state machine logic plus the sequence of transactions." (https://twitter.com/yminsky/status/950883598189686784 https://twitter.com/yminsky/status/950883598189686784)
- jpitz 9y agoThe argument is not that state machines are the child of FP, just that a common idiom in FP, Pattern Matching over ADTs, makes them easy to implement.
- seanmcdirmid 9y agoThis might be, but state machines are so common in imperative code, you could say they are common idiom there also. Pattern matching over ADTs only drives transitions; different representation of transitions can lead to different constructs being more convenient (e.g. if your transitions are just based on a finite set of values, you can use just dictionaries).
- jpitz 9y agoThat could very well be. My brain tends to map problems to ADTs with very low friction.