aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2019-03-31 00:17:36 +0100
committerDaniel Gröber <dxld@darkboxed.org>2019-03-31 00:18:58 +0100
commit19c77b1b65d580cd978b5c1c572445f24efe171a (patch)
tree530af21c7a962dc6ce4ec66094b90c6ddea41843
parenta612a11140d93bdaa416f16e2c77a23332e9d656 (diff)
Promote 'Ex' to exported API
We will need it for the project discovery module later.
-rw-r--r--lib/Distribution/Helper.hs1
-rw-r--r--src/CabalHelper/Compiletime/Types.hs30
-rw-r--r--tests/GhcSession.hs2
3 files changed, 30 insertions, 3 deletions
diff --git a/lib/Distribution/Helper.hs b/lib/Distribution/Helper.hs
index f38d6d5..bb1f67f 100644
--- a/lib/Distribution/Helper.hs
+++ b/lib/Distribution/Helper.hs
@@ -68,6 +68,7 @@ module Distribution.Helper (
, SProjType(..)
, demoteSProjType
, ProjLoc(..)
+ , Ex(..)
, Programs(..)
, defaultPrograms
diff --git a/src/CabalHelper/Compiletime/Types.hs b/src/CabalHelper/Compiletime/Types.hs
index 6b7d74a..9911aec 100644
--- a/src/CabalHelper/Compiletime/Types.hs
+++ b/src/CabalHelper/Compiletime/Types.hs
@@ -15,7 +15,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DefaultSignatures,
- StandaloneDeriving, GADTs, DataKinds, KindSignatures, RankNTypes #-}
+ StandaloneDeriving, GADTs, DataKinds, KindSignatures, RankNTypes, PolyKinds #-}
{-|
Module : CabalHelper.Compiletime.Types
@@ -105,6 +105,34 @@ data DistDir (pt :: ProjType) where
deriving instance Show (DistDir pt)
+-- | General purpose existential wrapper. Useful for hiding a phantom type
+-- argument.
+--
+-- Say you have:
+--
+-- @
+-- {-# LANGUAGE DataKinds, GADTS #-}
+-- data K = A | B | ...
+-- data Q k where
+-- QA :: ... -> Q 'A
+-- QB :: ... -> Q 'B
+-- @
+--
+-- and you want a list of @Q@. You can use @Ex@ to hide the phantom type
+-- argument and recover it later by matching on the GADT constructors:
+--
+-- @
+-- qa :: Q A
+-- qa = QA
+--
+-- qb :: Q B
+-- qb = QB
+--
+-- mylist :: [Ex Q]
+-- mylist = [Ex qa, Ex qb]
+-- @
+data Ex a = forall x. Ex (a x)
+
-- | Environment for running a 'Query'. The constructor is not exposed in the
-- API to allow extending it with more fields without breaking user code.
--
diff --git a/tests/GhcSession.hs b/tests/GhcSession.hs
index 46ccab9..2fda204 100644
--- a/tests/GhcSession.hs
+++ b/tests/GhcSession.hs
@@ -159,8 +159,6 @@ testLocPath (TN test_name) = (projdir, ".", cabal_file)
testLocPath (TF topdir projdir cabal_file) =
(topdir, projdir, cabal_file)
-data Ex a = forall x. Ex (a x)
-
-- | Check version bounds of tests against available versions, if successful run
-- the test.
checkAndRunTestConfig