You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately I think the answer is No and I'll tell you why:
Let's suppose Validation is a ZipFunctor which means that it has a zip operation which is the inverse of Functor's unzip (which is defined as unzip s = map fst s, map snd s).
Then we can do:
> zip (Validation<string,int>.Success 42) (Validation<string,float>.Failure "Error") ;;
val it : Validation<string,(int * float)> = Failure "Error"
and now
> unzip it ;;
val it : Validation<string,int> * Validation<string,float> =
(Failure "Error", Failure "Error")
but now
> it ||> zip;;
val it : Validation<string,(int * float)> = Failure "ErrorError"
so we came back to a different value !
Note however that Result seems to be well behaved in this regard:
> zip (Result<int,string>.Ok 42) (Result<float,string>.Error "No") ;;
[<Struct>]
val it : Result<(int * float),string> = Error "No"
> unzip it ;;
val it : Result<int,string> * Result<float,string> = (Error "No", Error "No")
> it ||> zip;;
[<Struct>]
val it : Result<(int * float),string> = Error "No"
Activity
gusty commentedon Feb 25, 2020
That's a very interesting question.
Unfortunately I think the answer is No and I'll tell you why:
Let's suppose Validation is a ZipFunctor which means that it has a
zipoperation which is the inverse of Functor'sunzip(which is defined asunzip s = map fst s, map snd s).Then we can do:
and now
but now
so we came back to a different value !
Note however that
Resultseems to be well behaved in this regard:Does it makes sense?
NickDarvey commentedon Feb 25, 2020
That does make sense. Thank you for the accessible explanation @gusty 😊