On 8/10/07, Shachaf Ben-Kiki <shachaf@gmail.com
> wrote:
Also consider using:
> data Step = Step { ..., scenario :: Scenario, ... }
Just to expand on Shachaf's answer, when defining a data type you can use a special record syntax to give names to each of the components, like this:
data Monkey = M { species :: Species, color :: Color }
This automatically gives you functions called 'species' and 'color' which you can apply to values of type Monkey to extract the relevant components. So in your case, you could write something like
data Step = Step { ..., owner :: Scenario, ... }
...which would give you the 'owner' function you defined above for free, without having to type it out.
To expand on Dan and Albert's answers, the 'functional idiom' would be to just write 'owner x' -- introducing something like a different definition of . to do 'record selection' might make things easier in the short term (
i.e. if you are used to programming in an OO paradigm) but seems quite detrimental in the long term. Trying to force Haskell to look and feel like other languages you are used to is like taking two of the wheels off your Porsche because you are used to riding a bicycle. =)
-Brent