Is it possible?, (there is a >>magic function) to simplify this:
insertTransaction :: Day -> Int -> Int -> MyReaderT Bool
insertTransaction day amount price = ....
logTransaction :: Int -> Int -> MyReaderT Bool
logTransaction amount price = do
day <- currentDay
insertTransaction day amount price
To this:
logTransaction :: Int -> Int -> MyReaderT Bool
logTransaction = currentDay `>>magic` insertTransaction
I think there should be one operator like >>magic but I can’t found it. Nor <*> neither <$>.
This isn’t really possible without typeclass trickery, because you’re trying to “lift” a function with an arbitrary number of arguments — which is, of course, not really a well-defined concept in Haskell, due to currying.
The best you’re likely to get in standard, readable Haskell is this:
I think this is probably fine — the proposed operator seems quite difficult to read to me, since it’s hard to tell how many arguments are being processed or where they’re going.
With the Strathclyde Haskell Enhancement preprocessor,
logTransactioncould be written as follows, using idiom brackets:Finally, it is technically possible to write
logTransactionin a point-free style, but I wouldn’t recommend it: