packages feed

record-hasfield 1.0 → 1.0.1

raw patch · 6 files changed

+107/−96 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- GHC.Records.Extra: instance forall k1 k2 a1 r2 (x1 :: k2) r1 (x2 :: k1) a2. (a1 Data.Type.Equality.~ r2, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2) => GHC.Records.Compat.HasField '(x1, x2) r1 a2
- GHC.Records.Extra: instance forall k1 k2 k3 a1 r2 a2 r3 (x1 :: k3) r1 (x2 :: k2) (x3 :: k1) a3. (a1 Data.Type.Equality.~ r2, a2 Data.Type.Equality.~ r3, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3) => GHC.Records.Compat.HasField '(x1, x2, x3) r1 a3
- GHC.Records.Extra: instance forall k1 k2 k3 k4 a1 r2 a2 r3 a3 r4 (x1 :: k4) r1 (x2 :: k3) (x3 :: k2) (x4 :: k1) a4. (a1 Data.Type.Equality.~ r2, a2 Data.Type.Equality.~ r3, a3 Data.Type.Equality.~ r4, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3, GHC.Records.Compat.HasField x4 r4 a4) => GHC.Records.Compat.HasField '(x1, x2, x3, x4) r1 a4
- GHC.Records.Extra: instance forall k1 k2 k3 k4 k5 a1 r2 a2 r3 a3 r4 a4 r5 (x1 :: k5) r1 (x2 :: k4) (x3 :: k3) (x4 :: k2) (x5 :: k1) a5. (a1 Data.Type.Equality.~ r2, a2 Data.Type.Equality.~ r3, a3 Data.Type.Equality.~ r4, a4 Data.Type.Equality.~ r5, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3, GHC.Records.Compat.HasField x4 r4 a4, GHC.Records.Compat.HasField x5 r5 a5) => GHC.Records.Compat.HasField '(x1, x2, x3, x4, x5) r1 a5
+ GHC.Records.Extra: instance forall k1 k2 a1 r2 (x1 :: k1) r1 (x2 :: k2) a2. (a1 GHC.Types.~ r2, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2) => GHC.Records.Compat.HasField '(x1, x2) r1 a2
+ GHC.Records.Extra: instance forall k1 k2 k3 a1 r2 a2 r3 (x1 :: k1) r1 (x2 :: k2) (x3 :: k3) a3. (a1 GHC.Types.~ r2, a2 GHC.Types.~ r3, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3) => GHC.Records.Compat.HasField '(x1, x2, x3) r1 a3
+ GHC.Records.Extra: instance forall k1 k2 k3 k4 a1 r2 a2 r3 a3 r4 (x1 :: k1) r1 (x2 :: k2) (x3 :: k3) (x4 :: k4) a4. (a1 GHC.Types.~ r2, a2 GHC.Types.~ r3, a3 GHC.Types.~ r4, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3, GHC.Records.Compat.HasField x4 r4 a4) => GHC.Records.Compat.HasField '(x1, x2, x3, x4) r1 a4
+ GHC.Records.Extra: instance forall k1 k2 k3 k4 k5 a1 r2 a2 r3 a3 r4 a4 r5 (x1 :: k1) r1 (x2 :: k2) (x3 :: k3) (x4 :: k4) (x5 :: k5) a5. (a1 GHC.Types.~ r2, a2 GHC.Types.~ r3, a3 GHC.Types.~ r4, a4 GHC.Types.~ r5, GHC.Records.Compat.HasField x1 r1 a1, GHC.Records.Compat.HasField x2 r2 a2, GHC.Records.Compat.HasField x3 r3 a3, GHC.Records.Compat.HasField x4 r4 a4, GHC.Records.Compat.HasField x5 r5 a5) => GHC.Records.Compat.HasField '(x1, x2, x3, x4, x5) r1 a5

Files

CHANGES.txt view
@@ -1,4 +1,6 @@ Changelog for record-hasfield +1.0.1, released 2024-01-21+    Add required extension for newer GHC 1.0, released 2019-03-21     Initial version
LICENSE view
@@ -1,4 +1,4 @@-Copyright Adam Gundry and Neil Mitchell 2018-2019.+Copyright Adam Gundry and Neil Mitchell 2018-2024. All rights reserved.  Redistribution and use in source and binary forms, with or without
README.md view
@@ -1,4 +1,4 @@-# record-hasfield [![Hackage version](https://img.shields.io/hackage/v/record-hasfield.svg?label=Hackage)](https://hackage.haskell.org/package/record-hasfield) [![Stackage version](https://www.stackage.org/package/record-hasfield/badge/nightly?label=Stackage)](https://www.stackage.org/package/record-hasfield) [![Build status](https://img.shields.io/travis/ndmitchell/record-hasfield/master.svg?label=Build)](https://travis-ci.org/ndmitchell/record-hasfield)+# record-hasfield [![Hackage version](https://img.shields.io/hackage/v/record-hasfield.svg?label=Hackage)](https://hackage.haskell.org/package/record-hasfield) [![Stackage version](https://www.stackage.org/package/record-hasfield/badge/nightly?label=Stackage)](https://www.stackage.org/package/record-hasfield) [![Build status](https://img.shields.io/github/actions/workflow/status/ndmitchell/record-hasfield/ci.yml?branch=master)](https://github.com/ndmitchell/record-hasfield/actions)  This package provides a version of "GHC.Records" as it will be after the implementation of [GHC proposal #42](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0042-record-set-field.rst), which reads:
record-hasfield.cabal view
@@ -1,13 +1,13 @@-cabal-version:      >= 1.18+cabal-version:      1.18 build-type:         Simple name:               record-hasfield-version:            1.0+version:            1.0.1 license:            BSD3 license-file:       LICENSE category:           Development author:             Neil Mitchell <ndmitchell@gmail.com> maintainer:         Neil Mitchell <ndmitchell@gmail.com>-copyright:          Adam Gundry and Neil Mitchell 2018-2019+copyright:          Adam Gundry and Neil Mitchell 2018-2024 synopsis:           A version of GHC.Records as available in future GHCs. description:     This package provides a version of "GHC.Records" as it will be after the implementation of@@ -15,7 +15,7 @@     plus some helper functions over it. homepage:           https://github.com/ndmitchell/record-hasfield#readme bug-reports:        https://github.com/ndmitchell/record-hasfield/issues-tested-with:        GHC==8.6.4, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2+tested-with:        GHC==9.8, GHC==9.6, GHC==9.4, GHC==9.2, GHC==9.0, GHC==8.10, GHC==8.8  extra-doc-files:     CHANGES.txt
src/GHC/Records/Compat.hs view
@@ -1,35 +1,36 @@-{-# LANGUAGE AllowAmbiguousTypes-           , FunctionalDependencies-           , ScopedTypeVariables-           , PolyKinds-           , TypeApplications-  #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-} --- | This module provides a version of "GHC.Records" as it will be after the implementation of---   <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0042-record-set-field.rst GHC proposal #42>.------   In future GHC versions it will be an alias for "GHC.Records".-module GHC.Records.Compat-    ( HasField(..)-    , getField-    , setField-    ) where+{- | This module provides a version of "GHC.Records" as it will be after the implementation of+  <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0042-record-set-field.rst GHC proposal #42>. --- | Constraint representing the fact that the field @x@ can be get and set on---   the record type @r@ and has field type @a@.  This constraint will be solved---   automatically, but manual instances may be provided as well.------   The function should satisfy the invariant:------ > uncurry ($) (hasField @x r) == r+  In future GHC versions it will be an alias for "GHC.Records".+-}+module GHC.Records.Compat (+    HasField (..),+    getField,+    setField,+) where++{- | Constraint representing the fact that the field @x@ can be get and set on+  the record type @r@ and has field type @a@.  This constraint will be solved+  automatically, but manual instances may be provided as well.++  The function should satisfy the invariant:++> uncurry ($) (hasField @x r) == r+-} class HasField x r a | x r -> a where     -- | Function to get and set a field in a record.     hasField :: r -> (a -> r, a)  -- | Get a field in a record.-getField :: forall x r a . HasField x r a => r -> a+getField :: forall x r a. (HasField x r a) => r -> a getField = snd . hasField @x  -- | Set a field in a record.-setField :: forall x r a . HasField x r a => r -> a -> r+setField :: forall x r a. (HasField x r a) => r -> a -> r setField = fst . hasField @x
src/GHC/Records/Extra.hs view
@@ -1,89 +1,97 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TupleSections #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wno-orphans #-}-{-# LANGUAGE AllowAmbiguousTypes-           , MultiParamTypeClasses-           , ScopedTypeVariables-           , PolyKinds-           , TypeApplications-           , FlexibleInstances-           , UndecidableInstances-           , DataKinds-           , GADTs-           , TupleSections-  #-} --- | Extensions over a future version of "GHC.Records".---   Provides the function 'modifyField' plus the orphan instances:------ * @HasField \'(x1,x2)@ for selecting first the @x1@ field, then the @x2@ field.---   Available for @()@ and tuples up to arity 5.------ * @HasField \"_1\" (a,b) a@ for selecting the first compomnent of a pair,---   plus similarly for all fields up of all tuples up to arity 5.------   Using these functions together you get:------ > modifyField @'("_1","_2") negate ((1,2),3,4,5) == ((1,-2),3,4,5)-module GHC.Records.Extra-    ( module GHC.Records.Compat-    , modifyField-    ) where+{- | Extensions over a future version of "GHC.Records".+  Provides the function 'modifyField' plus the orphan instances: +* @HasField \'(x1,x2)@ for selecting first the @x1@ field, then the @x2@ field.+  Available for @()@ and tuples up to arity 5.++* @HasField \"_1\" (a,b) a@ for selecting the first compomnent of a pair,+  plus similarly for all fields up of all tuples up to arity 5.++  Using these functions together you get:++> modifyField @'("_1","_2") negate ((1,2),3,4,5) == ((1,-2),3,4,5)+-}+module GHC.Records.Extra (+    module GHC.Records.Compat,+    modifyField,+) where+ import GHC.Records.Compat  -- | Modify a field in a record.-modifyField :: forall x r a . HasField x r a => r -> (a -> a) -> r+modifyField :: forall x r a. (HasField x r a) => r -> (a -> a) -> r modifyField r f = gen $ f val-    where (gen, val) = hasField @x r+  where+    (gen, val) = hasField @x r  instance HasField '() a a where     hasField r = (id, r)  instance (a1 ~ r2, HasField x1 r1 a1, HasField x2 r2 a2) => HasField '(x1, x2) r1 a2 where     hasField r = (gen1 . gen2, val2)-        where-            (gen1, val1) = hasField @x1 r-            (gen2, val2) = hasField @x2 val1+      where+        (gen1, val1) = hasField @x1 r+        (gen2, val2) = hasField @x2 val1 -instance (a1 ~ r2, a2 ~ r3, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3) =>-        HasField '(x1, x2, x3) r1 a3 where+instance+    (a1 ~ r2, a2 ~ r3, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3) =>+    HasField '(x1, x2, x3) r1 a3+    where     hasField = hasField @'(x1, '(x2, x3)) -instance (a1 ~ r2, a2 ~ r3, a3 ~ r4, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3, HasField x4 r4 a4) =>-        HasField '(x1, x2, x3, x4) r1 a4 where+instance+    (a1 ~ r2, a2 ~ r3, a3 ~ r4, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3, HasField x4 r4 a4) =>+    HasField '(x1, x2, x3, x4) r1 a4+    where     hasField = hasField @'(x1, '(x2, x3, x4)) -instance (a1 ~ r2, a2 ~ r3, a3 ~ r4, a4 ~ r5, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3, HasField x4 r4 a4, HasField x5 r5 a5) =>-        HasField '(x1, x2, x3, x4, x5) r1 a5 where+instance+    (a1 ~ r2, a2 ~ r3, a3 ~ r4, a4 ~ r5, HasField x1 r1 a1, HasField x2 r2 a2, HasField x3 r3 a3, HasField x4 r4 a4, HasField x5 r5 a5) =>+    HasField '(x1, x2, x3, x4, x5) r1 a5+    where     hasField = hasField @'(x1, '(x2, x3, x4, x5)) -instance HasField "_1" (a,b) a where-    hasField (a,b) = ((,b), a)-instance HasField "_2" (a,b) b where-    hasField (a,b) = ((a,), b)+instance HasField "_1" (a, b) a where+    hasField (a, b) = ((,b), a)+instance HasField "_2" (a, b) b where+    hasField (a, b) = ((a,), b) -instance HasField "_1" (a,b,c) a where-    hasField (a,b,c) = ((,b,c), a)-instance HasField "_2" (a,b,c) b where-    hasField (a,b,c) = ((a,,c), b)-instance HasField "_3" (a,b,c) c where-    hasField (a,b,c) = ((a,b,), c)+instance HasField "_1" (a, b, c) a where+    hasField (a, b, c) = ((,b,c), a)+instance HasField "_2" (a, b, c) b where+    hasField (a, b, c) = ((a,,c), b)+instance HasField "_3" (a, b, c) c where+    hasField (a, b, c) = ((a,b,), c) -instance HasField "_1" (a,b,c,d) a where-    hasField (a,b,c,d) = ((,b,c,d), a)-instance HasField "_2" (a,b,c,d) b where-    hasField (a,b,c,d) = ((a,,c,d), b)-instance HasField "_3" (a,b,c,d) c where-    hasField (a,b,c,d) = ((a,b,,d), c)-instance HasField "_4" (a,b,c,d) d where-    hasField (a,b,c,d) = ((a,b,c,), d)+instance HasField "_1" (a, b, c, d) a where+    hasField (a, b, c, d) = ((,b,c,d), a)+instance HasField "_2" (a, b, c, d) b where+    hasField (a, b, c, d) = ((a,,c,d), b)+instance HasField "_3" (a, b, c, d) c where+    hasField (a, b, c, d) = ((a,b,,d), c)+instance HasField "_4" (a, b, c, d) d where+    hasField (a, b, c, d) = ((a,b,c,), d) -instance HasField "_1" (a,b,c,d,e) a where-    hasField (a,b,c,d,e) = ((,b,c,d,e), a)-instance HasField "_2" (a,b,c,d,e) b where-    hasField (a,b,c,d,e) = ((a,,c,d,e), b)-instance HasField "_3" (a,b,c,d,e) c where-    hasField (a,b,c,d,e) = ((a,b,,d,e), c)-instance HasField "_4" (a,b,c,d,e) d where-    hasField (a,b,c,d,e) = ((a,b,c,,e), d)-instance HasField "_5" (a,b,c,d,e) e where-    hasField (a,b,c,d,e) = ((a,b,c,d,), e)+instance HasField "_1" (a, b, c, d, e) a where+    hasField (a, b, c, d, e) = ((,b,c,d,e), a)+instance HasField "_2" (a, b, c, d, e) b where+    hasField (a, b, c, d, e) = ((a,,c,d,e), b)+instance HasField "_3" (a, b, c, d, e) c where+    hasField (a, b, c, d, e) = ((a,b,,d,e), c)+instance HasField "_4" (a, b, c, d, e) d where+    hasField (a, b, c, d, e) = ((a,b,c,,e), d)+instance HasField "_5" (a, b, c, d, e) e where+    hasField (a, b, c, d, e) = ((a,b,c,d,), e)