# F＃：如何找到笛卡爾的力量

 let Cprod U V =
let mutable res = []
for u in U do
for v in V do
res <- res @ [[u;v]]
res


let Cpower U n =
let mutable V = U
for i=0 to n-1 do
V <- Dprod U V
V


Visual Studio說：錯誤在統一''a'和''列表'時，結果類型將是無限的。我會感謝任何幫助和鏈接。

## 最佳答案

// Cprod: seq<a> -> seq<a> -> a list list
let Cprod U V =
...

// Cpower: seq<a> -> int -> ???
let Cpower U n =
//V: seq<a>
let mutable V = U
//n: int
for i=0 to n-1 do
(* The next line implies two type constraints:
V: seq<a>
V: a list list *)
V <- Dprod U V
V


That V must be an seq<a> and an a list list, and that U and V must have the same type means that a = a list, which is what results in the "infinite type" error message (the infinity type is ... list list list list. Even though the value of V` is mutable, it must have a single type.