【发布时间】:2012-08-08 00:02:00
【问题描述】:
我正在尝试序列化 Contacts 类型,但我一直在定义 put 和 get?
import Control.Monad
import Data.Binary
type Name = String
type Address = String
data Contacts = Contacts [(Name, Address)] deriving (Show)
instance Binary Contacts where
put (Contacts [(n,a)]) = do ...
get = do ...
main :: IO ()
main = do
let c = Contacts [("gert","home")]
let e = encode c
let d = decode e
print d
【问题讨论】:
-
向我解释为什么像 this 这样的问题得到 +40 而我的得到 -1?
-
还有他们在stackoverflow.com/faq 中的任何内容会使这个问题成为一个坏问题吗?
-
IMO 您的问题往往有点含糊不清,而且涉及到无关紧要的、特定于域的代码(尽管这不是)。我认为通过更详细地隔离一个编程问题,而不是问“我的代码有什么问题”,你会做得更好。查看几个highly-voted questions tagged with haskell,了解是什么让他们成功。还有准确的stackoverflow.com/questions/how-to-ask。
-
如果您是 Haskell 的新手,那么您绝对不可能从 code.haskell.org/binary 转到我得到的答案。我尝试的所有代码都没有任何意义,只会混淆问题。如果你用谷歌搜索
haskell Data.Binary example,你甚至会看到我自己的问题在前 10 名结果中,因为缺少其他示例。如果您为 js java c c# bash 执行此操作...您将获得大量数据来查看。 -
最后,我似乎只是要求 2 行代码来帮助我。
标签: haskell