From b09a00426c4f72892f7863bbaaf688c21592dd03 Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 19 Mar 2019 12:53:50 +0300 Subject: Handle types with more than 3 constructors Particularly ((a :+: b) :+: (c :+: d)) combinations. --- Coalpit/Core.hs | 13 +++++++++++++ coalpit.cabal | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Coalpit/Core.hs b/Coalpit/Core.hs index e166af9..f8e90be 100644 --- a/Coalpit/Core.hs +++ b/Coalpit/Core.hs @@ -233,6 +233,19 @@ instance (Constructor conA, Constructor conB, GCoalpit a, GCoalpit b) => in USum (handleRecCon nameA opt path (Proxy :: Proxy (a p))) (handleRecCon nameB opt path (Proxy :: Proxy (b p))) +instance {-# OVERLAPPABLE #-} + (GCoalpit a, GCoalpit b) => GCoalpit (a :+: b) where + gArgParser opt = + L1 <$> gArgParser opt + <|> + R1 <$> gArgParser opt + gToArgs opt (L1 x) = gToArgs opt x + gToArgs opt (R1 x) = gToArgs opt x + gArgHelper opt path (Proxy :: Proxy ((a :+: b) p)) = + -- let nameA = conName (undefined :: a p) + -- in + USum (gArgHelper opt path (Proxy :: Proxy (a p))) + (gArgHelper opt path (Proxy :: Proxy (b p))) -- Record Selectors diff --git a/coalpit.cabal b/coalpit.cabal index e3248a1..4a6462a 100644 --- a/coalpit.cabal +++ b/coalpit.cabal @@ -1,5 +1,5 @@ name: coalpit -version: 0.1.1.0 +version: 0.1.1.1 synopsis: Command-line options and DSV parsing and printing description: This library generates parsers and printers for given data types, in the form of command-line -- cgit v1.2.3