[Haskell-beginners] State as function?

martin martin.drautzburg at web.de
Sun Apr 6 16:28:54 UTC 2014


Am 04/06/2014 04:05 PM, schrieb Daniel Trstenjak:

> 
> data StringState = Resting
>                  | Oscillating
>                  ...
> 
> data Guitar = Guitar
>    { string1 :: StringState
>    , string2 :: StringState
>    ...
>    }

Yes this, and also the information on which fret the finger is.

The problem with this approach is that I end up with two representations of GuitarString. One is the accessor functions
above, but there is also a datatype GuitarString which I need to express things like "put your finger on the nth fret of
the mth string".

I found myself mapping between these two representations, which is not hard to do, but it impairs clarity.





More information about the Beginners mailing list