i have a function: (*==) :: B -> (C -> IO a) -> IO a basically, it takes b, does something to it to make c, performs the action on c and returns the value. the Bs are basically Doubles, so we'll consider them as such for now. suppose I want to string together a bunch of these things...i can write: 5 *== \x -> 6 *== \y -> somefunctiononxandy x y but i'd really like to be able to write: 5 *== 6 *== somefunctiononxandy or, secondarily 5 *== (6 *== somefunctiononxandy) but i can't seem to get this to work and my brain is beginning to hurt. i suppose this is basically the same as wanting to write something like: action1 >>= action2 >>= somefunction instead of action1 >>= \x -> action2 >>= \y -> somefunction x y so if it can be done for >>=, i can make it to work. any advice? - Hal -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
Hal Daume III writes: : | 5 *== \x -> 6 *== \y -> somefunctiononxandy x y | | but i'd really like to be able to write: | | 5 *== 6 *== somefunctiononxandy : | any advice? If you want to do something akin to currying, to eliminate the explicit lambdas, I think you'll have to clutter up the right hand end of the expression instead. The basic problem seems to be that you're trying to match arguments to parameters in an order which goes against the expression's syntax. Contrast the following: 5 *== 6 *== somefunctiononxandy arg ---------------------------> param arg ---------------------------> param 5 *== 6 *== somefunctiononYandX arg ---------------------------------> param arg ---------------------> param So, there's a way using flip: infixr 1 *== a *== f = f a flip3 f a b c = f c b a test f3 = 5 *== 6 *== 7 *== flip3 f3 -- test (,,) --> (5,6,7) If you dislike having to use different clutter (flip, flip3, etc.) depending on the number of (*==)s in the expression, you could make (*==) a function of 3 parameters instead of 2, and use an argument accumulator: infixr 1 *== (a *== f) applyToOtherAs = f (($a) . applyToOtherAs) test f2 = 5 *== 6 *== ($f2) $ id -- test (,) --> (5,6) -- :t (*==) --> left as a strenuous exercise for the reader Regards, Tom
participants (2)
-
Hal Daume III -
Tom Pledger