You can simplify the function by removing the map and adding a dynamic downcast to 'a in the return expression of the seq comprehension.

Whether both parameters are required really depends on how you want to use this function. My guess is that both 'a and t are meant to refer to the same type, this type is statically known, it is an interface or abstract class, and implementations of it will be found in the plugin assemblies. In which case you can remove the t parameter and replace occurances of t with (type 'a). So your code might be written as

1
2
3
4
5
let create<'a> (mgr: PluginManager) =
  { for x in assemblies mgr
    for y in HA.types x
    when Helper.is_a (type 'a) y
    -> (HA.domain x).CreateInstanceAndUnwrap((HA.assembly x).FullName, y.FullName) :?> 'a}

See also [link:cs.hubfs.net] for a similar problem.

By on 12/21/2007 11:33 PM ()

Hi,

You are correct in that 'a and t refer to the same statically known type (which is an abstract class/interface).

I am actually the person who had started that last thread you reference as well :). Unluckily, the little gem (type 'a) didn't make it into the last thread, and I have just returned to working on that library after a long break.

Thank you very much for the answer, as I will be putting it to use immediately. I'm getting on quite well with F#, but there are still certain areas such as types (obviously), events and so on that confuse me with regards to how F# and the rest of .net interact.

Thanks again,

z.

By on 12/22/2007 12:22 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper