I can do (x : int array)
But I need only 300 elements array , so how do I (x : int[300]) ?
Can’t find such information over msdn )
@Marcelo Cantos No reason , but I always used sized arrays. Why not ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. The F# type system does not support types such as “array of size 300”, and even if it did, using the type system to check potential array overflows at compile time is too impractical to implement.
Besides, “has exactly 300 elements” is an useless property in F# in almost all situations, because there is a wealth of functions and primitives that work on arrays of arbitrary size without any risk of overflow (
maporiter, for instance). Why write code that works for 300 elements when you can just as easily write code that works for any number of elements ?If you really need to represent the “has exactly 300 elements” property, the simplest thing you could do is create a wrapper type around the native array type. This lets you restrict those operations that return arrays to only operations that respect the 300-element invariant (such as a
mapfrom another 300-element array, or acreatewhere the length property is always300). I’m afraid this isn’t as simple as you hoped, but since F# does not natively support 300-element arrays, you will need to describe all the function invariants yourself.