One way is to generate a DLL to disk, then load it at runtime and find your entry-point through reflection. You can find the MethodInfo on your type for your function and call it via an Invoke.

With the compile times for your generated code, i would first try building the result list via

1
2
3
4
let res = []
let res = x1 :: res
let res = x2 :: res
res

That may help. If not, can you send a sample to fsbugs@m...

Thanks.

By on 9/29/2006 5:59 AM ()

Hi,

First thanks for the tips on reflection which I have now got working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  exception Dynload_method of MethodInfo
  let outputs = 
    let assembly = Assembly.LoadFrom ("simple.dll") in
    let typ = assembly.GetType("Simple", true) in
    let methods = typ.GetMethods() in
    let func = 
      try
        Idioms.foreach methods (fun (m : MethodInfo) ->
          if m.Name = "simple"
          then raise (Dynload_method m)
        );
        failwith "Couldnt find correct method"
      with
      | Dynload_method m -> m
      | e -> raise e
    in
    unbox (func.Invoke(null,null))
  in

(please excuse the "worse than gotos" use of exception handling for flow control here, but I couldnt think of another way to do it).

I've sent some example code the fsbugs@.. which exposes the performance (both memory and time) problems I have seen.

Cheers,

Andy

By on 9/29/2006 8:27 AM ()

Exceptions are not cheap on .NET, so you will want to avoid them in cases which are not "exceptional". There are functions in MLLib.Array for finding an item in an Array, given a predicate or selector function.

1
2
Array.find : ('a -> bool) -> 'a array -> 'a
Array.first : ('a -> 'b option) -> 'a array -> 'b option 

See:

[link:research.microsoft.com]

For consistency with List, there *should* also be:

1
Array.tryfind : ('a -> bool) -> 'a array -> 'a option
By on 9/29/2006 10:24 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