F# Pattern matching and functions -


I tried to apply Fibonacci sequence in F # using pattern matching like this:

< Pre> let Fibonacci M = REC-FIB = function | (0, _, z) - & gt; Jade. (N, y, z) - & gt; Fib (N-1) Z (y + z) FIB Me 0 I hope that in the order of how far we are, the first argument to keep track of the next two For consistent terms in logic sequence

However, I am receiving a compile-time error on fib (n-1) z (y + z) :

  Type mismatch type A '-' 'B - & gt; 'C but given one', the resulting type will be infinite when 'one' and '' b -> 'C -> 'A'  

I tried to specify these types of types:

  Fibonacci M = two REC Fib = function. (0, _, z: int) - & gt; Jade. (N: int, y: int, z: int) - & gt; Fib (N-1) z (y + z) Fib M1  

and then I get a different compilation error at fib (n-1) :

  This value is not a function and can not be implemented  

I am still trying to get my head around functional programming I am I think that I can lack the understanding of this problem that what the first pattern really is. I want this to mean that when the position argument is zero, then it gives the second argument word.

Does anyone help me with this problem which is obviously due to some misunderstanding in my part

The problem is that you are calling a function with curious arguments when the actual argument is actually defined as expected:

  Fibonacci M = let RE Fb = function | (0, _, z) - & gt; Jade. (N, y, z) - & gt; Fiber (N-1, Z, Y + Z) Fib (M, 0, 1)  

That's because you are using the function logic In your case, use the option match

  against Tupal with Fibonacci M = REC FBB BC = match (A, B, C). (0, _, z) - & gt; Jade. (N, y, z) - & gt; Fib (N-1) Z (y + z) FIB Me 0 1  

You can think of a function on that argument on mail .


Comments