Hacker News new | ask | show | jobs
by hamidpalo 5423 days ago
While that's a very good example of what F# can do, I think the real value proposition of F# is that it can use anything from .NET. Take something like this for example:

  open System
  open System.Collections.Generic
  open System.Reflection
  
  type Config = string 
  type ISuperPlugin =
      abstract member Name : string
      abstract member Initialize : Config -> unit
  
  let loadedPlugins = Dictionary<string,ISuperPlugin>()
  
  let isPlugin (tp: Type) =
      tp.GetInterfaces()
      |> Seq.exists (fun t -> t.GetType() = typeof<ISuperPlugin>)
  
  let isPluginLoaded plugin =
      match loadedPlugins.TryGetValue(plugin) with
      | true, v -> true
      | _ -> false
  
  
  let loadPlugin typ = () // implement this
  
  let LoadPluginsFromAssembly path =
      let asm = Assembly.LoadFrom path
      asm.GetTypes()
      |> Seq.filter isPlugin
      |> Seq.filter (fun t -> not (isPluginLoaded t.Name))
      |> Seq.map loadPlugin
      |> ignore
  
  let loadAllPlugins plugins =
      plugins
      |> Seq.map (fun p -> async { LoadPluginsFromAssembly p })
      |> Async.Parallel
      |> ignore
Loads a bunch of plugins from assemblies in parallel. Haven't tested it but it should work with minor modifications to make it thread-safe.