在Elm中获取函数的类型签名

Mar*_*van 5 type-inference type-signature elm

我正在使用榆木0.18。

假设我有一个函数,将一堆我匆忙扔到一起的东西串在一起。它可以工作,但是我不确定它的类型签名是什么,我想榆木告诉我(或提示我)该类型签名。

例如,我使用graphql并具有一个接受graphql字符串,解码器(也没有类型签名)和a的Cmd Msg函数,并通过HttpBuilder运行它。

graphQLPost graphiql decoder msg =
    HttpBuilder.post (url ++ "api")
        |> HttpBuilder.withStringBody "text/plain" graphiql
        |> HttpBuilder.withExpect (Http.expectJson decoder)
        |> HttpBuilder.send msg
Run Code Online (Sandbox Code Playgroud)

这行得通,尽管我不知道为什么。我尝试将其与类型签名配合使用graphQLPost : String -> Json.Decode.Decoder -> Cmd Msg,但出现错误。

对我来说,弄清楚这种类型的签名并不像找到一种方法通过榆树诱导它们那样重要。是否可以输入命令elm-repl或可以告诉我签名的内容?

Cha*_*ert 4

Elm REPL 将为您执行此操作:

> import Http
> import HttpBuilder
> type Msg = Msg
> url = "..."
"..." : String
> graphQLPost graphiql decoder msg = \
|     HttpBuilder.post (url ++ "api") \
|         |> HttpBuilder.withStringBody "text/plain" graphiql \
|         |> HttpBuilder.withExpect (Http.expectJson decoder) \
|         |> HttpBuilder.send msg
<function>
    : String
      -> Json.Decode.Decoder a
      -> (Result.Result Http.Error a -> msg)
      -> Platform.Cmd.Cmd msg
Run Code Online (Sandbox Code Playgroud)

当您编写一个函数并点击 时<Enter>,它会向您显示签名。在这种情况下,签名是:

graphQLPost : String
      -> Json.Decode.Decoder a
      -> (Result.Result Http.Error a -> msg)
      -> Platform.Cmd.Cmd msg
Run Code Online (Sandbox Code Playgroud)