Google News
logo
F# - Interview Questions
What is an interface in F#?
F# provides Interface type. It provides pure abstraction. It is a collection of abstract methods.
 
Example :
type IEmployee =  
   abstract member ShowName : unit -> unit  
type Manager(id:int, name:string) =  
   interface IEmployee with  
      member this.ShowName() = printfn "Id = %d \nName = %s" id name  
  
let manager = new Manager(100,"RajKumar")  
//manager.ShowName()    // error: you can't directly access interface abstract method by using class object.  
// so, we need to upcast class type object to interface type by using :> operator.  
(manager :> IEmployee).ShowName()
Advertisement