首页 > 解决方案 > 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

标签: elm

解决方案


可以使用以下文档格式为模块指定文档:

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. 甚至还有一个与此相关的问题

另一方面,还有elm-oracle库,它允许您将文档提示集成到编辑器中(并且它已经集成到流行的编辑器中),甚至可以在命令行中运行它:

elm-oracle FILE query

推荐阅读