I play with Elm examples, and I noticed that field gives types Result. After getting stuck, I came up with this simplified case:
import Html exposing (text)
import String
f: Int -> Int
f x = x + 1
g: Result String Int -> Result String Int
g x = (Result.map f) x
main =
text ( toString ( g (String.toInt 5 ) ))
The result displays , and I would prefer it to display only . I know that it accepts any type and returns a string representation of This. So maybe I can change OK 6 6toStringtoString
- if the result
OK, then I can print the numerical result - if the result
Err, then I would like to make some kind of custom error message
Perhaps this is the reason andThen, as the operation + 1may fail.
andThen : Result e a -> (a -> Result e b) -> Result e b
andThen result callback =
case result of
Ok value -> callback value
Err msg -> Err msg
A definition is exactly what it does ... and is an instance . andThencase
andThen, case ? , . .