F # or monad (ROP) to create a function with two parameters

I use the chessie library of helper functions to execute ROP (or monad) https://github.com/fsprojects/Chessie/blob/master/src/Chessie/ErrorHandling.fs

However, I'm not sure how succinctly put together the following three functions together. Where twoInputFuncto evaluate only if func1 and func2 return success.

val func1 : int -> Result<Tp1, 'a>
val func2 : string -> Result<Tp2, 'a>
val twoInputFunc : par1:Tp1 -> Tpar2:Tp2 -> Result<Ta,'a>
+4
source share
1 answer

I think this should work:

let f x y = trial {
    let! a = func1 x
    let! b = func2 y
    return! twoInputFunc a b}

, a b, . func1 func2 , .

:

let g x y = flatten (twoInputFunc <!> func1 x <*> func2 y)

, , , monad join.

: Chessie, , FSharpPlus, generic ( Either), ( trial join flatten) monad.

+9

Source: https://habr.com/ru/post/1666585/


All Articles