相关疑难解决方法(0)

管理大型Haskell记录的更好方法是什么?

用字母替换字段名称,我有这样的情况:

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 ...

-- …
Run Code Online (Sandbox Code Playgroud)

haskell records

4
推荐指数
1
解决办法
309
查看次数

将函数应用于类型级别的记录中的所有字段

有没有办法在类型系统中轻松完成以下操作?

data Product = Product {
    id :: ProductId
  , name :: Text
  , sku :: SKU, quantity :: Int
  , description :: Maybe Text
  }

data Omittable a = Omit | Present a
type ProductWithOmittableFields = Omittable Product

-- ProductWithOmittableFields is now equivalent to:\
--
-- data ProductWithOmittableFields = ProductWithOmmitableFields { 
--     id :: Omittable ProductId
--    ,name :: Omittable Text
--    ,sku : : Omittable SKU
--    ,quantity :: Omittable Int
--    ,desciption :: Omittable (Maybe Text)
-- …
Run Code Online (Sandbox Code Playgroud)

haskell types

2
推荐指数
1
解决办法
237
查看次数

标签 统计

haskell ×2

records ×1

types ×1