What are potential alternative representations (e.g. using arrows, lenses, Haskell idioms, do syntax) of pointfree expressions that could read more like plain English?
Here is trivial example:
qNameIs :: String -> QName -> Bool
qNameIs = (. qName) . (==)
QName
is a record from Text.Xml
What are possible equivalent to qNameIs
but not pointful expressions? Ideally, ones that would show that first argument will be passed to (==)
and result will be evaluated with result of qName
applied to second argument of this expression?
You can take the .^ operator of the module Data.Function.Pointless:
import Data.Function.Pointless (.^)
qNameIs :: String -> QName -> Bool
qNameIs = (==) .^ qName
An example with arrows (its not elegant...):
qNameIs :: String -> QName -> Bool
qNameIs = curry $ uncurry (==) . second qName
You can also write a new operator:
with :: (a -> c -> d) -> (b -> c) -> a -> b -> d
with f g = (. g) . f
Then you can write:
qNameIs = (==) `with` qName
which can be read as "equal with qName" (you can also take another operator name).
In General you shall also have a look on the module Data.Composition (Unfortunately it does not help in your case...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With