877
877

Reputation: 187

F# type option problems

i have the following code:

let rec sums1 n = function
            | (a,b,x:int array,s,k) when (s<n&&b=x.Length-1) -> []//None
            | (a,b,x:int array,s,k) when (a=b&&((x.Length-1)=b))->[]// None 
            | (a,b,x,s,k) when (s=n) -> (Array.toList(Array.sub x a k)) 
            | (a,b,x,s,k) when (s<n) -> sums1 n (a,b+1,x,s+x.[b+1],k+1)
            | (a,b,x,s,k) when (s>n) -> sums1 n (a+1,b,x,s-x.[a],k-1)    
            | (a,b,c,d,e) -> []//None

let neco n s =match (sums1 n (0,-1,s,0,0)) with
        | [] ->None
        | x ->Some x
let ssum n xs:list<int> = neco n (List.toArray xs)

How it is possible that the compiler doesn't allow me to return from ssum value of type option< list < int > >. I will return this type, not something else. Have someone any idea?

Upvotes: 1

Views: 165

Answers (2)

Robert Jeppesen
Robert Jeppesen

Reputation: 7877

In this case, you can just let type inference do it's job and remove the type declaration:

 let ssum n xs = neco n (List.toArray xs)

Upvotes: 0

Brian
Brian

Reputation: 118865

I think you're just missing parens:

let ssum n (xs:list<int>) = neco n (List.toArray xs) 
           ^            ^

Without them, you're describing the return type of ssum, not the argument type of xs.

Upvotes: 5

Related Questions