<div dir="auto"><div dir="ltr">Hi,<div><br></div><div>We have a sum type of 151 constructors (and growing) in one project. There is a somewhat natural grouping of the constructors into 24 groups (with between 1 and 32 constructors in each group) so we used that to break it down into the two levels:</div><div><br></div><div>data Group1 = Ctor1 Int | Ctor2 Bool | ...</div><div>data Group2 = Ctor5 String | Ctor6 Double | ...</div><div>...</div><div>data A = Group1 Group1 | Group2 Group2 | ...<br></div><div><br></div><div>This wasn't enough, so then we cheated and wrote some code-gen. The datatype is described as data (think YAML or JSON) and then there's a short program which generates the declarations, including Haddock comments, and various useful functions such as somewhat-custom JSON serialisation. Each group gets its own module, which gives faster recompilation on changes. We could have used TemplateHaskell, except we wouldn't have got such nice Haddock docs (and, ew, TemplateHaskell) and it would all have had to have been in one module.</div><div><br></div><div>Hope that helps,</div><div dir="auto"><br></div><div dir="auto">David</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 August 2017 at 02:29, Adam Flott <span dir="ltr"><<a href="mailto:adam@adamflott.com" target="_blank">adam@adamflott.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a sum type with a lot of constructors and I'm not sure how to represent<br>
the type with maintainability in mind. For example,<br>
<br>
    data A = A1<br>
           | A2 Int<br>
           | A3 Text Int32 Bool<br>
           | ...<br>
           | A100 Bool<br>
<br>
Every inner type is concrete. There are 100+ constructors with no sign of ever<br>
getting reduced.<br>
<br>
What technique would you recommend to keep the sum type approach but not having<br>
to define them all in one spot? I'm thinking 1 inner type + 1 function to<br>
construct per file (if that's possible).<br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br></div>