将字段名替换成字母后,我遇到了如下情况:
data Foo = Foo { a :: Maybe ...
, b :: [...]
, c :: Maybe ...
, ... for a lot more fields ...
} deriving (Show, Eq, Ord)
instance Writer Foo where
write x = maybeWrite a ++
listWrite b ++
maybeWrite c ++
... for a lot more fields ...
parser = permute (Foo
<$?> (Nothing, Just `liftM` aParser)
<|?> ([], bParser)
<|?> (Nothing, Just `liftM` cParser)
... for a lot more fields ...
-- this is particularly hideous
foldl1 merge [foo1, foo2, ...]
merge (Foo a b c ...seriously a lot more...)
(Foo a' b' c' ...) =
Foo (max a a') (b ++ b') (max c c') ...
有哪些技术可以帮助我更好地管理这种增长?
在完美的世界中,a
、b
和c
都是同一类型,因此我可以将它们保存在一个列表中,但它们可能是许多不同的类型。我特别关注任何一种可以折叠记录而不需要大量模式的方法。
我正在使用这个大型记录来保存从排列解析vCard格式中得到的不同类型。
更新
Foo
可以是除记录之外的其他内容吗)? - AlecFoo
,而是我们必须获得关于Foo
需要解决的问题的信息才能做出判断。 - Bakuriu