Flip For Non-Numeric Data Type
App Development3 posts292 views7 likesLast activity Sep 2020
CA
carleslabonOP
Sep 2020Hello good evening. I just want to ask a sample of using flip within a non-numeric data type, since I’m having a hard time creating one. Thanks!
BE
bernhard
Sep 2020Maybe one related to your mapA, forA question:
forA = flip mapA
That is actually how forA is implemented.
flip just changes the order of the arguments of a two parameter function:
flip : (a -> b -> c) -> (b -> a -> c)
flip fn x y = fn y x
Note that I’ve added parentheses for clarity above. The actual signature is (a -> b -> c) -> b -> a -> c which is equivalent by associativity. But basically, stick a function with two parameters of types a and b in, get a function with two parameters of types b and a out.
ST
stefanobaghino-da
Sep 2020On a lighter note, your pointer made me notice this code that makes even too much sense:
github.comdigital-asset/daml/blob/cd4a06db95b454f9053d8accd2dbd14b8f55f6b8/compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml#L402-L404
- -- | `=<<` is `>>=` with its arguments flipped.
- (=<<) : Action m => (a -> m b) -> m a -> m b
- (=<<) = flip (>>=)