1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DuplicateRecordFields #-}
4{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE NoMonomorphismRestriction #-}
6{-# LANGUAGE PartialTypeSignatures #-}
7{-# LANGUAGE TypeApplications #-}
8{-# LANGUAGE UndecidableInstances #-}
10{-# OPTIONS_GHC -fno-warn-unused-imports #-}
14import Data.Function ((&))
15import Data.Generics.Internal.Lens
16import Data.Generics.Product
17import Data.Generics.Sum
24 } deriving (Show, Generic)
31 } deriving (Show, Generic)
34 = Animal' { name :: String, eats :: String, age :: Int }
35 | Human' { name :: String, age :: Int, address :: String, eats :: String }
36 deriving (Show, Generic)
39toby = Human { name = "Toby", age = 10, address = "London", eats = "Bread" }
41growUp :: Animal -> Animal
42growUp (Animal n a _) = Animal n (a + 10) "raw meat"
44data MyRecord = MyRecord { field1 :: Int, field2 :: String } deriving Generic
46--g :: Subtype s MyRecord => s -> String
47--g s = s ^. super @MyRecord . label @"field2"
49data Test a b = Test { fieldInt :: Int, fieldA :: a, fieldB :: b } deriving (Generic, Show)
51-- changedA :: Test Int String
53-- Test {fieldInt = 10, fieldA = 10, fieldB = "world"}
54changedA = Test 10 "hello" "world" & field @"fieldA" .~ (10 :: Int)
56-- changedB :: Test String Int
58-- Test {fieldInt = 10, fieldA = "hello", fieldB = 10}
59changedB = (Test 10 "hello" "world") & field @"fieldB" .~ (10 :: Int)
61--changedInt = set (field @"fieldInt") ("hello") (Test 10 "hello" "world")
68 deriving (Generic, Show)
76 deriving (Generic, Show)
79dog, cat, duck :: Animal2 Int
80dog = Dog (MkDog "Shep" 3 30)
85--dog' :: Animal2 String
86dog' = dog & _Ctor @"Dog" . field @"fieldA" .~ "now it's a String"
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