开发者

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 ne开发者_C百科co 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?


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.


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜