Why are the different signatures of these two methods?

Why do Bind1 and Bind2 have different signatures?

type T() =
  let bind(v, f) = v
  member self.Bind1 = bind
  member self.Bind2(a, b) = bind(a, b)

fsi reports them as

type T =
  class
    new : unit -> T
    member Bind2 : a:'a * b:'b -> 'a
    member Bind1 : (obj * obj -> obj)
  end

This happened when I was playing with some calculation expressions and couldn't understand why I was getting a Bind error message that was not defined. The style of Bind1 did not work, Bind2 did, and I could not understand why.

For the same objects, they return the same result:

> q.Bind1(1:>obj,3:>obj);;
val it : obj = 1
> q.Bind2(1:>obj,3:>obj);;
val it : obj = 1
> 

Using Microsoft F # Interactive, (c) Microsoft Corporation, All rights reserved F # Version 1.9.7.4, compilation for version .NET Framework version 4.0.21006

+3
source share
2 answers

Bind1 is a get property that returns a function, and bind2 is a function. You can see the get accessor if you are evaluating bind1 and bind2 from an instance.

> let t = new T();;
val t : T
> t.Bind1;;
val it : (obj * obj -> obj) = <fun:get_Bind1@3>
> t.Bind2;;
val it : ('a * 'b -> 'a) = <fun:it@10>

member self.Bind1
   with get() = bind

reflector, Bind1, obj .

internal class get_Bind1@7 : FSharpFunc<Tuple<object, object>, object>
{
    // Fields
    public T self;

    // Methods
    internal get_Bind1@7(T self)
    {
        this.self = self;
    }

    public override object Invoke(Tuple<object, object> tupledArg)
    {
        object v = tupledArg.get_Item1();
        object f = tupledArg.get_Item2();
        return this.self.bind<object, object>(v, f);
    }
}

, kvb , , .

type T<'a, 'b>() =
  let bind(v:'a, f:'b) = (v:'a)
  member self.Bind1 = bind
  member self.Bind2(a, b) = bind(a, b)

type T<'a,'b> =
  class
    new : unit -> T<'a,'b>
    member Bind2 : a:'a * b:'b -> 'a
    member Bind1 : ('a * 'b -> 'a)
  end
+7

, .NET, F # v f, - obj. , Bind1 ( ) .

+4

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


All Articles