Why is my code not compiling?

let sub (m:double[],n:double[]) : double[]=
    [| for i = 0 to Array.length m -1 do m.[i]-n.[i] |]

Error 1 This value is not a function and cannot be applied E: \ MyDocuments \ Visual Studio 2010 \ Projects \ curve intersection \ newton \ Module1.fs 27 21 newton

But it normal:

let a = [| "a"; "b"; "c"; "d"; "e"; "f" |]

for i = 0 to Array.length a - 1 do
    System.Console.WriteLine(a.[i])
+3
source share
3 answers

The spaces around the minus sign:

f -1   // means f(-1)

calls a function fwith an argument -1(unary minus). While

n - 1

and

n-1

- subtraction.

The compiler error reflects that

Array.length m -1

analyzes how

(Array.length m)(-1)

, , -1. int, , , -1.

+7

:

let sub (m:double[], n:double[]) : double[] =
    [| for i = 0 to Array.length m - 1 do yield m.[i] - n.[i] |]
+3

The format of your understanding of the list / array is incorrect.

you either use ->as a short stretch:

let a = [1;2;3]
[| for i in a -> i |]

or formally write yield:

[| for i in a do yield i |]
+1
source

Source: https://habr.com/ru/post/1761437/


All Articles