module Data.Singletons.TH (
singletons, singletonsOnly, genSingletons,
promote, promoteOnly, genDefunSymbols, genPromotions,
promoteEqInstances, promoteEqInstance,
singEqInstances, singEqInstance,
singEqInstancesOnly, singEqInstanceOnly,
singDecideInstances, singDecideInstance,
promoteOrdInstances, promoteOrdInstance,
promoteBoundedInstances, promoteBoundedInstance,
cases,
Sing(SFalse, STrue, STuple0, STuple2, STuple3, STuple4, STuple5, STuple6, STuple7),
module Data.Singletons,
PEq(..), If, sIf, (:&&), SEq(..),
POrd(..),
Any,
SDecide(..), (:~:)(..), Void, Refuted, Decision(..),
Proxy(..), KProxy(..), SomeSing(..),
Error, ErrorSym0,
TrueSym0, FalseSym0,
LTSym0, EQSym0, GTSym0,
Tuple0Sym0,
Tuple2Sym0, Tuple2Sym1, Tuple2Sym2,
Tuple3Sym0, Tuple3Sym1, Tuple3Sym2, Tuple3Sym3,
Tuple4Sym0, Tuple4Sym1, Tuple4Sym2, Tuple4Sym3, Tuple4Sym4,
Tuple5Sym0, Tuple5Sym1, Tuple5Sym2, Tuple5Sym3, Tuple5Sym4, Tuple5Sym5,
Tuple6Sym0, Tuple6Sym1, Tuple6Sym2, Tuple6Sym3, Tuple6Sym4, Tuple6Sym5, Tuple6Sym6,
Tuple7Sym0, Tuple7Sym1, Tuple7Sym2, Tuple7Sym3, Tuple7Sym4, Tuple7Sym5, Tuple7Sym6, Tuple7Sym7,
SuppressUnusedWarnings(..)
) where
import Data.Singletons
import Data.Singletons.Single
import Data.Singletons.Promote
import Data.Singletons.Prelude.Instances
import Data.Singletons.Prelude.Bool
import Data.Singletons.Prelude.Eq
import Data.Singletons.Prelude.Ord
import Data.Singletons.Types
import Data.Singletons.Void
import Data.Singletons.Decide
import Data.Singletons.TypeLits
import Data.Singletons.SuppressUnusedWarnings
import Language.Haskell.TH.Desugar
import Language.Haskell.TH.Desugar.Sweeten
import GHC.Exts
import Language.Haskell.TH
import Language.Haskell.TH.Syntax ( Quasi(..) )
import Data.Singletons.Util
import Control.Applicative
cases :: Quasi q
=> Name
-> q Exp
-> q Exp
-> q Exp
cases tyName expq bodyq = do
info <- reifyWithWarning tyName
dinfo <- dsInfo info
case dinfo of
DTyConI (DDataD _ _ _ _ ctors _) _ -> fmap expToTH $ buildCases ctors
_ -> fail $ "Using <<cases>> with something other than a type constructor: "
++ (show tyName)
where buildCases ctors =
DCaseE <$> (dsExp =<< expq) <*>
mapM (\con -> DMatch (conToPat con) <$> (dsExp =<< bodyq)) ctors
conToPat :: DCon -> DPat
conToPat (DCon _ _ name fields) =
DConPa name (map (const DWildPa) $ tysOfConFields fields)