
Hi all, Given the follwing function:
owner :: Step -> Scenario owner (Step id scenario action state response) = scenario
Is it possible to define the owner function in such way that I can write x.owner (returning the scenario related with the Step x)? Thanks in advance, Rodrigo.

Prelude> let (.) = flip ($) in 5 . odd True But please don't, the (.) operator is a sacred artifact in my religion, and I'd hate to see it desecrated... :( Dan rodrigo.bonifacio wrote:
Hi all,
Given the follwing function:
owner :: Step -> Scenario owner (Step id scenario action state response) = scenario
Is it possible to define the owner function in such way that I can write x.owner (returning the scenario related with the Step x)?
Thanks in advance,
Rodrigo.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

rodrigo.bonifacio wrote:
owner :: Step -> Scenario owner (Step id scenario action state response) = scenario
Is it possible to define the owner function in such way that I can write x.owner (returning the scenario related with the Step x)?
The . is already taken. Choose some other symbol, say & x & f = f x Now you can use x&owner. P.S. What's wrong with plain and simple "owner x"?

Hi all,
Given the follwing function:
owner :: Step -> Scenario owner (Step id scenario action state response) = scenario
Is it possible to define the owner function in such way that I can write x.owner (returning the scenario related with the Step x)?
Some people use (|>), which looks like an arrow:
(|>) :: a -> (a -> b) -> b x |> f = f x
Then you can use "step |> owner". Also consider using:
data Step = Step { ..., scenario :: Scenario, ... }
Shachaf

On 8/10/07, Shachaf Ben-Kiki
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
participants (5)
-
Albert Y. C. Lai
-
Brent Yorgey
-
Dan Weston
-
rodrigo.bonifacio
-
Shachaf Ben-Kiki