I am unclear what your actual question is, so here are a couple comments.

The 'mean' function you have is inefficient. If you intend to work with arrays, use Array.fold & Array.length; as it stands, e.g. Seq.length is O(N) as it re-walks the IEnumerable.

I don't think an array of shorts can be implicitly 'cast' to an IEnumerable<double> in any language (though I could be wrong). You want the F# and VB code to both use the same numeric data types. An array of int can be passed to a function expecting an IEnumerable<int> in every language, I think.

By on 5/3/2010 8:57 AM ()

1) I got the 'mean' function from an example in F# for Scientists. I was more concerning with passing the data, than the efficiency. Yet, I will be very interested in efficiency once I get the basics working, so I'll move to the array structure.

2) The actual question was, should I cast on the VB side or the F# side and what is the best internal format. From your answer, I should be good with maintaining an array on both sides.

3) I changed the '0.0' to '0', but now I get a cast error from int16 to int32. I'll keep playing around.

dgp

By on 5/3/2010 11:27 AM ()

See the docs

[link:msdn.microsoft.com]

to find out that e.g. "0s" is a signed 16-bit zero.

By on 5/3/2010 11:46 AM ()

You can perform the conversion on either side; on the F# side, your function might look like:

1
2
3
4
let mean (xs:seq<int16>) =
  xs
  |> Seq.map float
  |> Seq.average

This takes a sequence, but since arrays are sequences this should work on your VB data without any problems. The key is the first step, which converts the int16 values to floats by mapping over the sequence. In other words, you can pass an int16[] where a seq<int16> is expected, but you can't pass an int16[] where a seq<float> is expected.

By on 5/3/2010 11:42 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