Elm函数可以有文档字符串吗?

时间:2018-08-06 06:32:10

标签: elm

Python有它们,我发现它们非常有用:

def awesome_fn(x, y):
    """"
    Calculates some awesome function of x and y.
    """"
    .
    .
    .

然后在iPython REPL中,您可以使用

进行查询
In [1]: awesome_fn?
Signature: awesome_fn(x, y)
Docstring: Calculates some awesome function of x and y.
File:      ...
Type:      function

1 个答案:

答案 0 :(得分:5)

可以使用以下documentation format指定模块的文档:

module Maybe exposing (Maybe(Just,Nothing), andThen, map, withDefault, oneOf)

{-| This library fills a bunch of important niches in Elm. A `Maybe` can help
you with optional arguments, error handling, and records with optional fields.

# Definition
@docs Maybe

# Common Helpers
@docs map, withDefault, oneOf

# Chaining Maybes
@docs andThen

-}

以及一种方法:

{-| Convert a list of characters into a String. Can be useful if you
want to create a string primarly by consing, perhaps for decoding
something.

    fromList ['e','l','m'] == "elm"
-}
fromList : List Char -> String
fromList = ...

但是到目前为止,尚无法从repl查看这些文档。甚至还有an issue与之相关。

另一方面,有elm-oracle库,该库可让您将文档提示集成到编辑器中(并且已经集成到the popular ones中),甚至可以在命令行中以以下方式运行: >

elm-oracle FILE query