let y() = Success (fun x -> x + 1) <*> (Success 3)
나는 다음과 같은 오류를 얻을 다음과 같은 유형 및 멤버 함수
type Result<'TSuccess, 'TError> =
| Success of 'TSuccess
| Error of 'TError list
with
member this.apply fn =
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])
다음과 같은 인라인 기능
let inline (<*>) (f: ^A) (t:^A) =
let apply' = (^A : (member apply : ^A -> ^A) (t, f))
apply'
그리고이 호출이 사이트를 감안할 때
let y() = Success (fun x -> x + 1) <*> (Success 3);;
-----------^^^^^^^^^^^^^^^^^^^^^^^^
/Users/robkuz/stdin(473,12): error FS0001: Type constraint mismatch.
The type
Result<'a,'c>
is not compatible with type
Result<('a -> 'b),'c>
The resulting type would be infinite when unifying ''a' and ''a -> 'b'
,
이 모든 것은 Haskells 실용적을 모방하려는 시도이며, 서명은
(<*>) :: forall f a b. Apply f => f (a -> b) -> f a -> f b
해야하지만 F 번호
이 일어날 수 있도록하는 방법에 어떤 아이디어에서 그것을 표현하는 방법이 없습니다 AFAIK 해달라고?
@Thomas가 제공하는 솔루션은 귀하의 경우에는 괜찮지만 기본 유형 (목록, 배열, 옵션)에서는 작동하지 않으며 모나드와 자동으로 작동하지 않습니다. [더 완벽한 해결책] (https://github.com/gmpl/FsControl/blob/master/FsControl.Core/Functor.fs#L133)이 있습니다. – Gustavo