How do I write this member constraint in F#?

It’s not explicitly writing the constraints that is the issue, it’s that the syntax is not so nice that you can place a member constraint on a parameter and then invoke the member in the usual way. The body of walk_the_creature and walk_the_creature2 would be the same here:

let inline walk_the_creature_2 (creature:^a when ^a:(member Walk : unit -> unit)) =
    (^a : (member Walk : unit -> unit) creature)

Leave a Comment