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