Variable.ConstrainBetween doesn't work with F# when the argument contains double? RRS feed

  • Question

  • If I do 

        let x = Variable.GaussianFromMeanAndVariance(0.0, 1.0)
        Variable.ConstrainBetween(x, 0.01.0)

    If It will trigger error that "the type float is not compatible with the type variable<float>"

    However, I can do such thing in C#

                var x = Variable.GaussianFromMeanAndVariance(0.0, 1.0);
                Variable.ConstrainBetween(x, 0.0, 1.0);

    Why is that? is there any workaround?  (besides define a variable and set its observed value as such).

    • Edited by colinfang Monday, October 13, 2014 5:04 PM
    Monday, October 13, 2014 5:03 PM


  • Hello,

    The C# user can rely on an implicit cast from T to Variable<T> defined in the Infer.NET Compile dll but F# doesn't, AFAIK, recognize these sorts of implicit cast (probably because they interfere with type inference).

    The workaround is to wrap your constant argument c with a call to Variable.Constant(c), or define your own F# function to do this for you.





    • Edited by Claudio Russo Friday, October 24, 2014 2:34 PM
    • Marked as answer by colinfang Friday, October 24, 2014 4:22 PM
    Friday, October 24, 2014 2:33 PM