4 ms·
Is then executed something like: foldr f LightOff input_stream
by jbritton 3y ago
Is then executed something like:
foldr f LightOff input_stream
- galaxyLogic 3y agoIt seems to me it calculates the result given some input. Can you incrementally give it new inputs and have the result depend on not only the new input but also all previous inputs? Where are the previous inputs and results (= state) of the calculation stored which allow the next calculation depend on previous results? In some variable?
- jbritton 3y ago# foldr above was a mistake # foldl state = LightOff while data { input = get_next(data) state = f(state, input) }
- mrkeen 3y agoSure, but I've run after the shifting goal post enough. I want you to translate the above state machine to a Turing Machine, or demonstrate in any way how a TM is a tool or model which brings any kind of clarity or simplicity to any modelling, design, compilation or coding activity.
- da39a3ee 3y agoThat's not a property of "basic" state machines, right? Their transition doesn't depend on the history, just on current state and perhaps an event. So it's not clear why you're bringing that up when you were asking about how to think of FP from a state machine point of view.
- galaxyLogic 3y agoThe example in Haskell is great and sheds light on how you can "model" state-machines in a functional language. My concern was the suggestion by the article that state-machines are somehow the basis of all computation. Turing machines intuitively look like machines with state. Functional programs not so much. Here's a simple example which I'm not saying proves my point but I have a question about: I have a program which calculates the average temperature of the year so far. You input today's temperature into it and it calculates and outputs the new updated average. If it is implemented as a functional program I can see how it can be given a time-series as input and it outputs the average. But today is a new day and I have a new temperature measurement which I give to my program. If it really is something I could call a "state-machine" it should be able to calculate the new average for me. But to do that it would need to have all the previous inputs held somewhere in its "state". Is there a functional program that can do that and give me the updated average temperature? Examples in JavaScript please if possible. Not everybody understands Haskell. Or is it something that can be done only in Haskell?
- da39a3ee 3y agofunction updateAverage(averageAsOfYesterday, todayTemp, todayDayOfYear) { yesterdayDayOfYear = todayDayOfYear - 1 sumOfAllTempsUpToAndIncludingYesterday = yesterdayDayOfYear * averageAsOfYesterday return (sumOfAllTempsUpToAndIncludingYesterday + todayTemp) / todayDayOfYear }