diff options
author | Adam Gundry <adam@well-typed.com> | 2015-11-17 15:50:33 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-11-17 16:58:49 +0100 |
commit | 7b962bab384e2ae85b41d30f503c3d0295b0214f (patch) | |
tree | aa93fb85a17988e6abdcaea362fbe6ae64a478d7 /libraries | |
parent | acce37f38bc3867f86cf717694915746bb2f278e (diff) | |
download | haskell-7b962bab384e2ae85b41d30f503c3d0295b0214f.tar.gz |
Implement OverloadedLabels
See
https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/OverloadedLabels
for the big picture.
Reviewers: goldfire, simonpj, austin, hvr, bgamari
Reviewed By: simonpj, bgamari
Subscribers: kosmikus, thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D1331
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/OverloadedLabels.hs | 48 | ||||
-rw-r--r-- | libraries/base/base.cabal | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/libraries/base/GHC/OverloadedLabels.hs b/libraries/base/GHC/OverloadedLabels.hs new file mode 100644 index 0000000000..f4a76cf8ea --- /dev/null +++ b/libraries/base/GHC/OverloadedLabels.hs @@ -0,0 +1,48 @@ +{-# LANGUAGE NoImplicitPrelude + , MultiParamTypeClasses + , MagicHash + , KindSignatures + , DataKinds + #-} + +----------------------------------------------------------------------------- +-- | +-- Module : GHC.OverloadedLabels +-- Copyright : (c) Adam Gundry 2015 +-- License : see libraries/base/LICENSE +-- +-- Maintainer : cvs-ghc@haskell.org +-- Stability : internal +-- Portability : non-portable (GHC extensions) +-- +-- This module defines the `IsLabel` class is used by the +-- OverloadedLabels extension. See the +-- <https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/OverloadedLabels wiki page> +-- for more details. +-- +-- The key idea is that when GHC sees an occurrence of the new +-- overloaded label syntax @#foo@, it is replaced with +-- +-- > fromLabel (proxy# :: Proxy# "foo") :: alpha +-- +-- plus a wanted constraint @IsLabel "foo" alpha@. +-- +----------------------------------------------------------------------------- + +-- Note [Overloaded labels] +-- ~~~~~~~~~~~~~~~~~~~~~~~~ +-- An overloaded label is represented by the 'HsOverLabel' constructor +-- of 'HsExpr', which stores a 'FastString'. It is passed through +-- unchanged by the renamer, and the type-checker transforms it into a +-- call to 'fromLabel'. See Note [Type-checking overloaded labels] in +-- TcExpr for more details in how type-checking works. + +module GHC.OverloadedLabels + ( IsLabel(..) + ) where + +import GHC.Base ( Symbol ) +import GHC.Exts ( Proxy# ) + +class IsLabel (x :: Symbol) a where + fromLabel :: Proxy# x -> a diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal index 7c89be4cfa..190309799e 100644 --- a/libraries/base/base.cabal +++ b/libraries/base/base.cabal @@ -247,6 +247,7 @@ Library GHC.Natural GHC.Num GHC.OldList + GHC.OverloadedLabels GHC.PArr GHC.Pack GHC.Profiling |