From 19c77b1b65d580cd978b5c1c572445f24efe171a Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Sun, 31 Mar 2019 00:17:36 +0100 Subject: Promote 'Ex' to exported API We will need it for the project discovery module later. --- src/CabalHelper/Compiletime/Types.hs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') 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 . {-# 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. -- -- cgit v1.2.3