metadata.xml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
  3. <pkgmetadata>
  4. <maintainer type="project">
  5. <email>haskell@gentoo.org</email>
  6. <name>Gentoo Haskell</name>
  7. </maintainer>
  8. <longdescription>
  9. In Haskell 98 the name of a record field
  10. is automatically also the name of a function which gets the value
  11. of the according field.
  12. E.g. if we have
  13. data Pair a b = Pair
  14. first :: a, second :: b
  15. then
  16. &gt; first :: Pair a b -&gt; a
  17. &gt; second :: Pair a b -&gt; b
  18. However for setting or modifying a field value
  19. we need to use some syntactic sugar, which is often clumsy.
  20. modifyFirst :: (a -&gt; a) -&gt; (Pair a b -&gt; Pair a b)
  21. modifyFirst f r\@(Pair
  22. first=a
  23. ) = r
  24. first = f a
  25. With this package you can define record field accessors
  26. which allow setting, getting and modifying values easily.
  27. The package clearly demonstrates the power of the functional approach:
  28. You can combine accessors of a record and sub-records,
  29. to make the access look like the fields of the sub-record belong to the main record.
  30. Example:
  31. &gt; *Data.Accessor.Example&gt; (first^:second^=10) (('b',7),"hallo")
  32. &gt; (('b',10),"hallo")
  33. You can easily manipulate record fields in a 'Control.Monad.State.State' monad,
  34. you can easily code 'Show' instances that use the Accessor syntax
  35. and you can parse binary streams into records.
  36. See @Data.Accessor.Example@ for demonstration of all features.
  37. It would be great if in revised Haskell versions the names of record fields
  38. are automatically 'Data.Accessor.Accessor's
  39. rather than plain @get@ functions.
  40. For now, the package @data-accessor-template@ provides Template Haskell functions
  41. for automated generation of 'Data.Acesssor.Accessor's.
  42. See also the other @data-accessor@ packages
  43. that provide an Accessor interface to other data types.
  44. The package @enumset@ provides accessors to bit-packed records.
  45. For similar packages see @lenses@ and @fclabel@.
  46. A related concept are editors
  47. &lt;http://conal.net/blog/posts/semantic-editor-combinators/&gt;.
  48. Editors only consist of a modify method
  49. (and @modify@ applied to a 'const' function is a @set@ function).
  50. This way, they can modify all function values of a function at once,
  51. whereas an accessor can only change a single function value,
  52. say, it can change @f 0 = 1@ to @f 0 = 2@.
  53. This way, editors can even change the type of a record or a function.
  54. An Arrow instance can be defined for editors,
  55. but for accessors only a Category instance is possible ('(.)' method).
  56. The reason is the @arr@ method of the @Arrow@ class,
  57. that conflicts with the two-way nature (set and get) of accessors.
  58. </longdescription>
  59. </pkgmetadata>