Code: Select all

`foo :: Int -> Int`

foo X = div ((f X) + (g X) + (h X)) ((a X) + (b X) + (c X)

where

Code: Select all

`a,b,c,f,g,h :: Int -> Int`

and something about the code looks a bit clunky because X is repeated so much.

Ideally I would like to have

Code: Select all

`(+!) f g x = (f x) + (g x)`

(/!) f g x = div (f x) (g x)

or

Code: Select all

`bar op f g x = op (f x) (g x)`

(+!) = bar (+)

(/!) = bar (/)

then I could write foo nicely as

Code: Select all

`foo = (f +! g +! h) /! (a +! b +! c)`

However, the two/three lines to define +! and /! seem like a lot of overhead.

Is something like this already built into Haskell, so I can use this idea without writing more code?

----

also as a quick side question, it seems that if i have

Code: Select all

`id i = (sort [1000,999..0]) !! i`

or even

Code: Select all

`id i = let xs = sort [1000,999..0] in xs !! i`

the list gets resorted every time I call id. Is there a way of writing this function so that the list is only sorted once?