유형 시스템에서 다음을 쉽게 수행 할 수 있습니까? 유형 수준에서 기록의 모든 분야에 적용되는유형 수준의 레코드에있는 모든 필드에 함수 적용
그것은 기본적으로 용기의 일종이다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)
-- }
(펑?).
이 아이디어가 확장 가능한 레코드 라이브러리로 더 잘 표현되어 있습니까?
편집 사용 사례는 사용자가 변경 한 필드 집합을 나타내는 ProductWithOmittableFields
을 UI 레이어에서 가져옵니다. 우리는 DB에서 Product
을 얻을 것이다, 우리는 Product
"이 아이디어는 확장 가능한 레코드 라이브러리로 더 잘 표현됩니까?" 거기에는 "generics-sop"이라는 라이브러리가 있습니다. 다음 질문을 참조하십시오. http://stackoverflow.com/questions/39020787/is-there-a-way-to-apply-maybe-constructor-to-each-field-of-record-with-generics and http :// /stackoverflow.com/questions/38248692/whats-a-better-way-of-managing-large-haskell-records – danidiaz