1{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE DuplicateRecordFields #-}
5{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE NoMonomorphismRestriction #-}
8{-# LANGUAGE PartialTypeSignatures #-}
9{-# LANGUAGE Rank2Types #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE TypeApplications #-}
12{-# LANGUAGE UndecidableInstances #-}
13{-# OPTIONS_GHC -Wno-missing-signatures #-}
14{-# OPTIONS_GHC -fno-warn-unused-imports #-}
18import Data.Function ((&))
19import Data.Generics.Internal.Lens
20import Data.Generics.Product
21import Data.Generics.Sum
23import Data.Generics.Labels
29 } deriving (Show, Generic)
36 } deriving (Show, Generic)
39 = Animal' { name :: String, eats :: String, age :: Int }
40 | Human' { name :: String, age :: Int, address :: String, eats :: String }
41 deriving (Show, Generic)
44toby = Human { name = "Toby", age = 10, address = "London", eats = "Bread" }
46growUp :: Animal -> Animal
47growUp (Animal n a _) = Animal n (a + 10) "raw meat"
49data MyRecord = MyRecord { field1 :: Int, field2 :: String } deriving Generic
51--g :: Subtype s MyRecord => s -> String
52--g s = s ^. super @MyRecord . label @"field2"
54data Test a b = Test { fieldInt :: Int, fieldA :: a, fieldB :: b } deriving (Generic, Show)
56-- changedA :: Test Int String
58-- Test {fieldInt = 10, fieldA = 10, fieldB = "world"}
59changedA = Test 10 "hello" "world" & field @"fieldA" .~ (10 :: Int)
61-- changedB :: Test String Int
63-- Test {fieldInt = 10, fieldA = "hello", fieldB = 10}
64changedB = (Test 10 "hello" "world") & field @"fieldB" .~ (10 :: Int)
66--changedInt = set (field @"fieldInt") ("hello") (Test 10 "hello" "world")
73 deriving (Generic, Show)
81 deriving (Generic, Show)
85dog = Dog (MkDog "Shep" 3 30)
87-- TODO: the error message for this case is ugly
95-- deriving (Generic, Show)
97--dog' :: Animal2 String
98dog' = dog & _Ctor @"Dog" . field @"fieldA" .~ "now it's a String"
101 ( HasPosition 15 s t a String
102 , HasField "test" s' t' a' b'
103 , HasField "bar" a' b' s t
105stuff r = r & field @"test" . field @"bar" . position @15 .~ "hello"
108 ( HasPosition 15 s t a String
109 , HasField "test" s' t' a' b'
110 , HasField "bar" a' b' s t
112stuff' r = r & #test . #bar . position @15 .~ "hello"
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