2
給這個以下類型和其apply
如何定義類型參數列表?
type Result<'TSuccess, 'TError> =
| Success of 'TSuccess
| Error of 'TError
with
member this.apply (fn:'a) : 'b =
match (fn, this) with
| Success(f), Success(x) -> Success(f x)
| Error(e), Success(_) -> Error(e)
| Success(_), Error(e) -> Error(e)
| Error(e1), Error(e2) -> Error(List.concat [e1;e2]);;
成員實現我得到這樣的警告(等等)
member this.apply (fn:'a) : 'b =
-----------^^^^
/Users/robkuz/stdin(385,12): warning FS0064: This construct causes code to
be less generic than indicated by the type annotations. The type variable
'TError has been constrained to be type ''a list'.
而這個錯誤
type Result<'TSuccess, 'TError> =
-----------------------^^^^^^^
/Users/robkuz/stdin(381,24): error FS0663: This type parameter has been used
in a way that constrains it to always be ''a list'
我試圖將其更改爲
type Result<'TSuccess, 'TError list> =
和
type Result<'TSuccess, List<'TError>> =
兩個給我一個語法錯誤。
我能做些什麼來解決這個問題?
'| | 'TError list'錯誤? – ildjarn
這應該如何工作?看起來好像'fn'應該是'Result <'a ->'b,'TError list>'?但是您已經將類型指定爲「a」。 – Lee