1{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE DuplicateRecordFields #-}
5{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE NoMonomorphismRestriction #-}
8{-# LANGUAGE OverloadedLabels #-}
9{-# LANGUAGE PartialTypeSignatures #-}
10{-# LANGUAGE Rank2Types #-}
11{-# LANGUAGE ScopedTypeVariables #-}
12{-# LANGUAGE TypeApplications #-}
13{-# LANGUAGE UndecidableInstances #-}
14{-# OPTIONS_GHC -Wno-missing-signatures #-}
15{-# OPTIONS_GHC -fno-warn-unused-imports #-}
19import Data.Function ((&))
20import Data.Generics.Internal.VL.Lens
21import Data.Generics.Product
22import Data.Generics.Sum
24import Data.Generics.Labels
25import Data.Generics.Internal.VL.Iso
26import Data.Generics.Internal.VL.Prism
27import Data.Generics.Internal.Profunctor.Lens
28import Data.Generics.Internal.Profunctor.Iso
29import Data.Generics.Internal.Profunctor.Prism
35 } deriving (Show, Generic)
42 } deriving (Show, Generic)
45 = Animal' { name :: String, eats :: String, age :: Int }
46 | Human' { name :: String, age :: Int, address :: String, eats :: String }
47 deriving (Show, Generic)
50toby = Human { name = "Toby", age = 10, address = "London", eats = "Bread" }
52growUp :: Animal -> Animal
53growUp (Animal n a _) = Animal n (a + 10) "raw meat"
55data MyRecord = MyRecord { field1 :: Int, field2 :: String } deriving Generic
57--g :: Subtype s MyRecord => s -> String
58--g s = s ^. super @MyRecord . label @"field2"
60data Test a b = Test { fieldInt :: Int, fieldA :: a, fieldB :: b } deriving (Generic, Show)
62-- changedA :: Test Int String
64-- Test {fieldInt = 10, fieldA = 10, fieldB = "world"}
65changedA = Test 10 "hello" "world" & field @"fieldA" .~ (10 :: Int)
67-- changedB :: Test String Int
69-- Test {fieldInt = 10, fieldA = "hello", fieldB = 10}
70changedB = (Test 10 "hello" "world") & field @"fieldB" .~ (10 :: Int)
72--changedInt = set (field @"fieldInt") ("hello") (Test 10 "hello" "world")
79 deriving (Generic, Show)
87 deriving (Generic, Show)
91dog = Dog (MkDog "Shep" 3 30)
93-- TODO: the error message for this case is ugly
101-- deriving (Generic, Show)
103--dog' :: Animal2 String
104dog' = dog & _Ctor @"Dog" . field @"fieldA" .~ "now it's a String"
107 ( HasPosition 15 s t a String
108 , HasField "test" s' t' a' b'
109 , HasField "bar" a' b' s t
111stuff r = r & field @"test" . field @"bar" . position @15 .~ "hello"
114 ( HasPosition 15 s t a String
115 , HasField "test" s' t' a' b'
116 , HasField "bar" a' b' s t
118stuff' r = r & #test . #bar . position @15 .~ "hello"
125modifyFoo2 :: Foo (Either String) Int -> Foo Maybe Int
126modifyFoo2 x = x & field @"foo1" .~ pure (1 :: Int)
132modifiedBar = (Bar ("hello", "world")) & field @"barField" .~ ('c', 1 :: Int)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list