File: Private.hs

package info (click to toggle)
haskell-data-accessor 0.2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: haskell: 458; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 668 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Data.Accessor.Private where

{- |
The accessor function we use,
has a record value as first argument
and returns the content of a specific record field
and a function that allows to overwrite that field with a new value.

In former version of a package
we used a function that resembled the state monad.
However this required to use an 'undefined'
in the implementation of the @get@ function.
-}
newtype T r a  =  Cons {decons :: r -> (a, a -> r)}

compose :: T a b -> T b c -> T a c
compose f g = Cons $ \ aOld ->
   let (bOld, aSetB) = decons f aOld
       (cOld, bSetC) = decons g bOld
   in  (cOld, aSetB . bSetC)

self :: T r r
self = Cons $ \r -> (r, id)