Skip to content
Discussions/App Development/Flip For Non-Numeric Data TypeForum ↗

Flip For Non-Numeric Data Type

App Development3 posts292 views7 likesLast activity Sep 2020
CA
carleslabonOP
Sep 2020

Hello 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 2020

Maybe 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 2020

On a lighter note, your pointer made me notice this code that makes even too much sense:

github.com

digital-asset/daml/blob/cd4a06db95b454f9053d8accd2dbd14b8f55f6b8/compiler/damlc/daml-stdlib-src/DA/Internal/Prelude.daml#L402-L404

  1. -- | `=<<` is `>>=` with its arguments flipped.
  2. (=<<) : Action m => (a -> m b) -> m a -> m b
  3. (=<<) = flip (>>=)
← Back to Discussions