Google News
logo
F# - Interview Questions
What is a delegate in F#?
In F#, delegates are reference types. It allows us to call the function as an object. It is a feature of this language. It gives an advantage over the other functional programming languages.
 
Example :
type Deligate() =  
  static member mul(a : int, b : int) = a * b  
  member x.Mul(a : int, b : int) = a * b  
type Multiply = delegate of (int * int) -> int  
  
let getIt (d : Multiply) (a : int) (b: int) =  
   d.Invoke(a, b)  
let d : Multiply = new Multiply( Deligate.mul )  
for (a, b) in [(5, 8) ] do  
  printfn "%d * %d = %d" a b (getIt d a b)
Advertisement