|
The same syntax works across a range of constructs in Haskell, Scala and Idris. (+) <$> getx <*> gety
This could be:* summing two reads in a Transaction, * summing two parsed numbers in a Parser, * summing two Nullable values into one Nullable value, * producing a Validated<T> by validating two of its parts which require validation, * and on and on. It's even the cartesian product when run on lists: let suits = ["♠", "♥", "♦", "♣"]
let nums = concat [["A"], map show [2..10], ["J","Q","K"]]
let cards = (++) <$> nums <*> suits
putStrLn (unwords (take 15 cards))
A♠ A♥ A♦ A♣ 2♠ 2♥ 2♦ 2♣ 3♠ 3♥ 3♦ 3♣ 4♠ 4♥ 4♦
Swift, Roc, Rust and JS have specialised their syntax for just one of these concerns.Also, it looks like you can just do it with ! in Haskell: https://hackage.haskell.org/package/monadic-bang |
Yes, although it's slightly clumsy.