6 people like it.

Useful operator definition for interop with C#

invokes op_Implicit when applied (for implicit conversions). I have found this to be very convenient when using C# libraries

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x)

(*
//Example based on Tensorflow.Net

open Tensorflow
let tf = Tensorflow.Binding.tf
let modelFile = @"C:\s\ground_speed\uncased_L-12_H-768_A-12\bert_model.ckpt.meta"
let graph = tf.Graph().as_default()
let saver = tf.train.import_meta_graph(modelFile)

//convert Operation to Tensor using implicit conversion operator

let input_tensor : Tensor = !> graph.OperationByName("Placeholder") 

//alternatively have to do this:
let op = graph.OperationByName("Placeholder")
let tensor = new Tensor(op,0,TF_DataType.TF_INT32)


*)
val x : 'a (requires member op_Implicit)

More information

Link:http://fssnip.net/7Y6
Posted:4 years ago
Author:Faisal Waris
Tags: c# , interoperability