1

I am having serious difficulty coming up with a definition for condition in the following code. Hoping for an example and insight:

// a computation expression builder class
type Builder() =
    .
    .
    .

    [<CustomOperation( "condition",
      MaintainsVariableSpaceUsingBind = true )>]
    member this.Condition(p, [<ProjectionParameter>] b) = 
        condition p b

let attemp = AttemptBuilder()

let test =
    attempt { let x, y = exp1, exp2
              condition booleanExpr(x, y)   
              return (x, y) }

I presume b is implicitly ( fun x, y -> booleanExpr(x, y) ). The term booleanExpr(x, y) is just some Boolean expression involving x and y.

Sasha Babaei
  • 455
  • 3
  • 8
  • 2
    What are you trying to achieve here? Also, see [how to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – scrwtp Aug 23 '17 at 22:00
  • 1
    This is it ... on page 475 of Expert F# 4.0, you could see this example for a custom conditional operator to replace `if`/`then`. The value`condition` is not specifically defined. – Sasha Babaei Aug 23 '17 at 22:28

1 Answers1

0

Found It:

let condition p guard = ( fun () ->
    match p() with
    | Some x when guard x -> Some x
    | _ -> None )
Sasha Babaei
  • 455
  • 3
  • 8