6 ms·
Definitely doesn't look as clean as the example above, or as clean as the Swift equivalent of await x + y
by superlopuh 2y ago
Definitely doesn't look as clean as the example above, or as clean as the Swift equivalent of
await x + y
- mrkeen 2y agoThe 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 https://hackage.haskell.org/package/monadic-bang
- tome 2y ago> it looks like you can just do it with ! in Haskell Yes, although it's slightly clumsy. example = do let suits = ["♠", "♥", "♦", "♣"] let nums = concat [["A"], map show [2..10], ["J","Q","K"]] let cards = do pure (!nums ++ !suits) putStrLn (unwords (take 15 cards)) ghci> example A♠ A♥ A♦ A♣ 2♠ 2♥ 2♦ 2♣ 3♠ 3♥ 3♦ 3♣ 4♠ 4♥ 4♦