Metadata revisions for partial-records-0.1.0.0

Package maintainers and Hackage trustees are allowed to edit certain bits of package metadata after a release, without uploading a new tarball. Note that the tarball itself is never changed, just the metadata that is stored separately. For more information about metadata revisions, please refer to the Hackage Metadata Revisions FAQ.

No. Time User SHA256
-r1 (partial-records-0.1.0.0-r1) 2019-10-15T04:30:30Z mniip faf609a3c46c9e071171639a7610edd6e8aa27b04f06f1d05950074a7b118a89
  • Changed synopsis from

    Template haskell utilities for constructing records with
    default values
    to
    Template haskell utilities for constructing records with default values

  • Changed description from

    If you have a datatype with a lot of default-able fields, e.g.
    
    > data Foo =
    >   { fld1 :: Maybe Int
    >   , fld2 :: Maybe Char
    >   , fld3 :: Word
    >   }
    
    and you want to avoid the the boilerplate of writing all the default values
    every time you construct a record of this type, you could write a "default
    value" of this type:
    
    > defaultFoo :: Foo
    > defaultFoo = Foo { fld1 = Nothing, fld2 = Nothing, fld3 = 0 }
    
    You could then use record modification syntax to make necessary changes to
    this value. But perhaps you can't/don't want to provide default values for
    /all/ of the fields, but only some of them? You could implement a "default
    smart constructor" that would take the non-optional arguments and then fill in
    the optional ones like so:
    
    > defaultFoo :: Word -> Foo
    > defaultFoo x = Foo { fld1 = Nothing, fld2 = Nothing, fld3 = x }
    
    But then you lose the benefit of record syntax: you can't name the fields
    you're providing values for.
    
    This package reconciles the two problems: with only a little bit of Template
    Haskell it provides a way to construct a record with optional fields while
    also letting you refer to the names of those fields. You make two splices:
    
    > mkToPartial ''Foo
    >   -- defines 'mkfld1', 'mkfld2', 'mkfld3'
    > mkFromPartial "mkFoo" [t|Foo|] [|Foo { fld1 = Nothing, fld2 = Nothing }
    >   |]
    >   -- defines 'mkFoo'
    
    And then you can use them like so:
    
    > val :: Foo
    > val = mkFoo
    >   $ mkfld3 123
    >   ? mkfld1 (Just 456)
    > -- val = Foo { fld1 = Just 456, fld2 = Nothing, fld3 = 123 }
    
    The Template Haskell splice lets you define default values for a subset of the
    fields, and those defaults will be used when you call @mkFoo@. You can list
    fields in any order, but if you omit a mandatory field (one that doesn't have
    a default), that would be a type error at compile time.
    
    You can make multiple 'Data.Partial.TH.mkFromPartial' splices, this is
    occasionally useful for parameterized types, for example:
    
    > data Bar a =
    >   { bar1 :: Maybe Int
    >   , bar2 :: a
    >   }
    > mkToPartial ''Bar
    > mkFromPartial "mkBar" [t|forall a. Bar a|]
    >   [|Bar { bar1 = Nothing }
    >   |]
    >   -- mkBar :: ... -> Bar a, and bar2 is a required field
    > mkFromPartial "mkBarMaybe" [t|forall a. Bar (Maybe a)|]
    >   [|Bar { bar1 = Nothing, bar2 = Nothing }
    >   |]
    >   -- mkBarMaybe :: ... -> Bar (Maybe a), and bar2 is an optional field
    to
    If you have a datatype with a lot of default-able fields, e.g.
    
    > data Foo =
    >   { fld1 :: Maybe Int
    >   , fld2 :: Maybe Char
    >   , fld3 :: Word
    >   }
    
    and you want to avoid the the boilerplate of writing all the default values
    every time you construct a record of this type, you could write a "default
    value" of this type:
    
    > defaultFoo :: Foo
    > defaultFoo = Foo { fld1 = Nothing, fld2 = Nothing, fld3 = 0 }
    
    You could then use record modification syntax to make necessary changes to
    this value. But perhaps you can't / don't want to provide default values for
    /all/ of the fields, but only some of them? You could implement a "default
    smart constructor" that would take the non-optional arguments and then fill in
    the optional ones like so:
    
    > defaultFoo :: Word -> Foo
    > defaultFoo x = Foo { fld1 = Nothing, fld2 = Nothing, fld3 = x }
    
    But then you lose the benefit of record syntax: you can't name the fields
    you're providing values for.
    
    This package reconciles the two problems: with only a little bit of Template
    Haskell it provides a way to construct a record with optional fields while
    also letting you refer to the names of those fields. You make two splices:
    
    > mkToPartial ''Foo
    >   -- defines 'mkfld1', 'mkfld2', 'mkfld3'
    > mkFromPartial "mkFoo" [t|Foo|] [|Foo { fld1 = Nothing, fld2 = Nothing }
    >   |]
    >   -- defines 'mkFoo'
    
    And then you can use them like so:
    
    > val :: Foo
    > val = mkFoo
    >   $ mkfld3 123
    >   ? mkfld1 (Just 456)
    > -- val = Foo { fld1 = Just 456, fld2 = Nothing, fld3 = 123 }
    
    The Template Haskell splice lets you define default values for a subset of the
    fields, and those defaults will be used when you call @mkFoo@. You can list
    fields in any order, but if you omit a mandatory field (one that doesn't have
    a default), that would be a type error at compile time.
    
    You can make multiple 'Data.Partial.TH.mkFromPartial' splices, this is
    occasionally useful for parameterized types, for example:
    
    > data Bar a =
    >   { bar1 :: Maybe Int
    >   , bar2 :: a
    >   }
    > mkToPartial ''Bar
    > mkFromPartial "mkBar" [t|forall a. Bar a|]
    >   [|Bar { bar1 = Nothing }
    >   |]
    >   -- mkBar :: ... -> Bar a, and bar2 is a required field
    > mkFromPartial "mkBarMaybe" [t|forall a. Bar (Maybe a)|]
    >   [|Bar { bar1 = Nothing, bar2 = Nothing }
    >   |]
    >   -- mkBarMaybe :: ... -> Bar (Maybe a), and bar2 is an optional field

-r0 (partial-records-0.1.0.0-r0) 2019-10-15T04:23:58Z mniip 255bfb1fddb56973cc98cdd414b638e0ea5064c0985494addb8a5b789c3cba80