summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2015-08-01 10:52:39 +0200
committerGabor Greif <ggreif@gmail.com>2015-08-02 20:10:44 +0200
commit37227d3400549c2a6844dfb8c34c0738edc69ecc (patch)
treef307f796b3530962257c0362b1a2398b6da6d16b /compiler
parentd9b618ff78e13f5fe7ae53e4363c658eb805785f (diff)
downloadhaskell-37227d3400549c2a6844dfb8c34c0738edc69ecc.tar.gz
Make BranchFlag a new kind
this is resolving an old TODO comment
Diffstat (limited to 'compiler')
-rw-r--r--compiler/types/CoAxiom.hs27
1 files changed, 13 insertions, 14 deletions
diff --git a/compiler/types/CoAxiom.hs b/compiler/types/CoAxiom.hs
index cd8607a4bb..9a85185cc6 100644
--- a/compiler/types/CoAxiom.hs
+++ b/compiler/types/CoAxiom.hs
@@ -1,12 +1,12 @@
-- (c) The University of Glasgow 2012
-{-# LANGUAGE CPP, DeriveDataTypeable, GADTs, ScopedTypeVariables #-}
+{-# LANGUAGE CPP, DataKinds, DeriveDataTypeable, GADTs, KindSignatures, ScopedTypeVariables, StandaloneDeriving #-}
-- | Module for coercion axioms, used to represent type family instances
-- and newtypes
module CoAxiom (
- Branched, Unbranched, BranchIndex, BranchList(..),
+ BranchFlag, Branched, Unbranched, BranchIndex, BranchList(..),
toBranchList, fromBranchList,
toBranchedList, toUnbranchedList,
brListLength, brListNth, brListMap, brListFoldr, brListMapM,
@@ -108,13 +108,6 @@ declaring whether it is known to be a singleton or not. The list of branches
is stored using a special form of list, declared below, that ensures that the
type variable is accurate.
-As of this writing (Dec 2012), it would not be appropriate to use a promoted
-type as the phantom type, so we use empty datatypes. We wish to have GHC
-remain compilable with GHC 7.2.1. If you are revising this code and GHC no
-longer needs to remain compatible with GHC 7.2.x, then please update this
-code to use promoted types.
-
-
************************************************************************
* *
Branch lists
@@ -125,11 +118,17 @@ code to use promoted types.
type BranchIndex = Int -- The index of the branch in the list of branches
-- Counting from zero
--- the phantom type labels
-data Unbranched deriving Typeable
-data Branched deriving Typeable
-
-data BranchList a br where
+-- promoted data type
+data BranchFlag = Branched | Unbranched
+type Branched = 'Branched
+deriving instance Typeable 'Branched
+type Unbranched = 'Unbranched
+deriving instance Typeable 'Unbranched
+-- By using type synonyms for the promoted constructors, we avoid needing
+-- DataKinds and the promotion quote in client modules. This also means that
+-- we don't need to export the term-level constructors, which should never be used.
+
+data BranchList a (br :: BranchFlag) where
FirstBranch :: a -> BranchList a br
NextBranch :: a -> BranchList a br -> BranchList a Branched