For the http request functions, both the Elm tutorial and the docs suggest passing a constructor function (e.g. GotText) to an expect function (e.g. expectString), for the expect field, e.g:
type Msg
= GotText (Result Http.Error String)
getPublicOpinion : Cmd Msg
getPublicOpinion =
Http.get
{ url = "https://elm-lang.org/assets/public-opinion.txt"
, expect = Http.expectString GotText
}
I understand this, but it seems to me that constraining the API to require a constructor function (e.g. GotText) is overly restrictive.
For example, it is possible to use identity to extract the constructor function GotText from the request function get:
getPublicOpinion = Cmd.map GotText (
Http.get
{ url = "https://elm-lang.org/assets/public-opinion.txt"
, expect = Http.expectString identity
})
But that begs the question: Why does the http API require the constructor function at all*?
* Or at least allow us to omit the expect field and return Result Http.Error String.