[Haskell-beginners] State as function?
martin.drautzburg at web.de
Sun Apr 6 13:20:14 UTC 2014
in my program, I have to keep track of the State of a Guitar, i.e. where the fingers are on the fretboard and which
strings are currently playing. Thus I need to associate some information to each of the 6 strings.
I started out with assoc lists and hashmaps. However, I found it diffiult to ensure that all 6 GuitarString have a
something attached and found myself messing with Maybes. In the real world, there is no way a GuitarString can have "no
state at all", while the HashMap approach would provide this option.
Then I thought, hey I really just need a function from GuitarString to something, so why not make that function the
state? That was certainly doable, but I still have my doubts whether this is the correct way of doing such things.
What is particularly worrying is that a state change will most likely affect a single GuitarString only. So I need to
create a new function which answers the new something for that particular GuitarString and calls the old function for
strings whose state hasn't changed. So with many state changes, I will get a deep call hierarchy. Though in the real
world this is unlikely to cause problems, it makes me worry.
What do you think?
More information about the Beginners