2

我正在尝试为界面上的记录字段编写黑线鳕。只导出了一些字段,所以我只希望记录其中的一些。我在这里阅读了文档页面:http ://www.haskell.org/haddock/doc/html/ch03s02.html#id565178

但是,我似乎无法让它发挥作用。这是我尝试编写黑线鳕的部分:

{-|
Describes a Clients connection and provides an interface for
storing data associated with the client. Each client will be given
a unique cid and are Eq if their cid's are Eq.

A ClientConn comes packaged with two functions for storing additional
information in Strings, lookup and modify. The lookup function
takes a key and returns the current value of the key or the empty
string if it has never been set. The modify function
takes a key and value and updates it such that the next call to
lookup with that key will return the value provided.
-}
data ClientConn = ClientConn { -- | The Unique ID for this client
                               cid       :: Integer,
                               -- | A lookup function for this client
                               lookup    :: (String -> IO String),
                               -- | A modify function for this client
                               modify    :: (String -> String -> IO ()),
                               chandle   :: Handle,
                               host      :: Net.HostName,
                               pid       :: Net.PortNumber,
                               msgList  :: List String,
                               dead      :: MVar Bool,
                               timestamp :: TimeStamp,
                               tid       :: MVar (ThreadId, ThreadId),
                               lock      :: MVar Lock.Lock}

数据类型的注释正确显示在生成的黑线鳕中。但是,不会生成任何记录。我希望它为 cid、查找和修改记录生成。

提前致谢!

完整的源代码可以在这里找到:https ://github.com/jcollard/simple-server/blob/master/Network/SimpleServer.hs

4

1 回答 1

3

不幸的是,黑线鳕目前不支持仅将记录的少数字段的文档显示为该记录的字段。您可以通过导出所有字段来解决此问题:

module Foo (ClientConn(..)) where ...

或通过导出字段,但不作为字段:

module Foo (ClientConn, cid, lookup, modify) where ...

在后一种情况下,文档不会自动指出这些函数实际上是字段,但它们可以在记录语法中使用。

于 2013-02-16T22:25:44.240 回答