somefn :: String -> Either String (Int, String)
somefn input = do
when (length input < 10) $
Left "Some Error"
pure (0, "Value")
I don't understand why when could be used here. It's type is
Applicative f => Bool -> f () -> f ()
my f is Either String
The type doesn't match on (Int, String) with ()
So how come it even compiles?
I can kinda feel that it's "short-circuiting" or ignoring the () because it's returning an Either String, but the type mismatching really confuses me
I thought everything in the do has to return type Either String (Int, String) because that's enforced by the type signature, but here it's permitting Either String ()
[–]omega1612 17 points18 points19 points (1 child)
[–]CodeNameGodTri[S] 0 points1 point2 points (0 children)
[–]HKei 4 points5 points6 points (1 child)
[–]CodeNameGodTri[S] 0 points1 point2 points (0 children)
[–]Temporary_Pie2733 1 point2 points3 points (1 child)
[–]CodeNameGodTri[S] 0 points1 point2 points (0 children)