File: Test62.hs

package info (click to toggle)
haskell-generic-lens 2.2.2.0-2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 228 kB
  • sloc: haskell: 1,378; makefile: 6
file content (20 lines) | stat: -rw-r--r-- 639 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# LANGUAGE DataKinds, DeriveGeneric, TypeApplications #-}
module Test62 (example, example_) where
import Data.Generics.Product (field, field_, position, position_)
import Data.Generics.Internal.VL.Lens (set)
import GHC.Generics (Generic)

data Foo a = Foo { bar :: Bar a } deriving Generic
data Bar a = Bar { x :: a, y :: a } deriving Generic

example :: Foo ()
example =
  set (field @"bar" . position @1) ()
  . set (position @1 . field @"y") ()
  $ Foo{ bar = Bar{ x = (), y = () } }

example_ :: Foo ()
example_ =
  set (field_ @"bar" . position_ @1) ()
  . set (position_ @1 . field_ @"y") ()
  $ Foo{ bar = Bar{ x = (), y = () } }