[Haskell-beginners] State as function?
karl at karlv.net
Sun Apr 6 17:39:25 UTC 2014
On Sun, Apr 6, 2014, at 09:28 AM, martin wrote:
> 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".
You could try using an array:
data StringIndex = S1 | S2 | S3 | S4 | S5 | S6 deriving (Eq, Ord, Enum,
Bounded, Read, Show)
type Guitar = Array StringIndex StringState
The Enum and Bounded constraints on StringIndex let you do fun things
allStrings = [minBound .. maxBound]
More information about the Beginners