[commit: ghc] wip/hasfield: Add GHC.Records module including HasField class (760d4e8)

git at git.haskell.org git at git.haskell.org
Mon May 16 08:07:11 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/hasfield
Link       : http://ghc.haskell.org/trac/ghc/changeset/760d4e8399ce3394a7a685ad67cc093455a380b9/ghc

>---------------------------------------------------------------

commit 760d4e8399ce3394a7a685ad67cc093455a380b9
Author: Adam Gundry <adam at well-typed.com>
Date:   Tue Dec 22 16:10:46 2015 +0000

    Add GHC.Records module including HasField class


>---------------------------------------------------------------

760d4e8399ce3394a7a685ad67cc093455a380b9
 compiler/prelude/PrelNames.hs | 14 ++++++++++++++
 libraries/base/GHC/Records.hs | 30 ++++++++++++++++++++++++++++++
 libraries/base/base.cabal     |  1 +
 3 files changed, 45 insertions(+)

diff --git a/compiler/prelude/PrelNames.hs b/compiler/prelude/PrelNames.hs
index c83c73f..6fa7c40 100644
--- a/compiler/prelude/PrelNames.hs
+++ b/compiler/prelude/PrelNames.hs
@@ -326,6 +326,9 @@ basicKnownKeyNames
         -- Overloaded labels
         isLabelClassName,
 
+        -- Overloaded record fields
+        hasFieldClassName,
+
         -- Source locations
         callStackDataConName, callStackTyConName,
         srcLocDataConName,
@@ -503,6 +506,9 @@ gHC_FINGERPRINT_TYPE = mkBaseModule (fsLit "GHC.Fingerprint.Type")
 gHC_OVER_LABELS :: Module
 gHC_OVER_LABELS = mkBaseModule (fsLit "GHC.OverloadedLabels")
 
+gHC_RECORDS :: Module
+gHC_RECORDS = mkBaseModule (fsLit "GHC.Records")
+
 mAIN, rOOT_MAIN :: Module
 mAIN            = mkMainModule_ mAIN_NAME
 rOOT_MAIN       = mkMainModule (fsLit ":Main") -- Root module for initialisation
@@ -1349,6 +1355,11 @@ isLabelClassName :: Name
 isLabelClassName
  = clsQual gHC_OVER_LABELS (fsLit "IsLabel") isLabelClassNameKey
 
+-- Overloaded record fields
+hasFieldClassName :: Name
+hasFieldClassName
+ = clsQual gHC_RECORDS (fsLit "HasField") hasFieldClassNameKey
+
 -- Source Locations
 callStackDataConName, callStackTyConName, srcLocDataConName :: Name
 callStackDataConName
@@ -1501,6 +1512,9 @@ semigroupClassKey, monoidClassKey :: Unique
 semigroupClassKey = mkPreludeClassUnique 46
 monoidClassKey    = mkPreludeClassUnique 47
 
+hasFieldClassNameKey :: Unique
+hasFieldClassNameKey = mkPreludeClassUnique 48
+
 ---------------- Template Haskell -------------------
 --      THNames.hs: USES ClassUniques 200-299
 -----------------------------------------------------
diff --git a/libraries/base/GHC/Records.hs b/libraries/base/GHC/Records.hs
new file mode 100644
index 0000000..16c10d0
--- /dev/null
+++ b/libraries/base/GHC/Records.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE NoImplicitPrelude
+           , MultiParamTypeClasses
+           , MagicHash
+           , KindSignatures
+           , DataKinds
+           , FunctionalDependencies
+  #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  GHC.Records
+-- Copyright   :  (c) Adam Gundry 2015
+-- License     :  see libraries/base/LICENSE
+--
+-- Maintainer  :  cvs-ghc at haskell.org
+-- Stability   :  internal
+-- Portability :  non-portable (GHC extensions)
+--
+--
+-----------------------------------------------------------------------------
+
+module GHC.Records
+       ( HasField(..)
+       ) where
+
+import GHC.Base ( Symbol )
+import GHC.Exts ( Proxy# )
+
+class HasField (x :: Symbol) r a | x r -> a where
+  getField :: Proxy# x -> r -> a
diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal
index cd77e55..8b99821 100644
--- a/libraries/base/base.cabal
+++ b/libraries/base/base.cabal
@@ -262,6 +262,7 @@ Library
         GHC.Ptr
         GHC.Read
         GHC.Real
+        GHC.Records
         GHC.RTS.Flags
         GHC.ST
         GHC.StaticPtr



More information about the ghc-commits mailing list