<div dir="ltr">If you have that many constructors, you probably aren't pattern-matching against the whole thing everywhere. So you could extract the few functions that use the entire type for case analysis into a typeclass, make each constructor its own type, and implement the typeclass:<div><br></div><div>Instead of:</div><div><br></div><div>something :: A -> IO ()</div><div>something A1 = putStrLn "hello"</div><div>something (A2 _) = putStrLn "world"</div><div><br></div><div>Use:</div><div><br></div><div>data A1</div><div>data A2 = A2 Int</div><div><br></div><div>class RelatedConst a of</div><div> something :: a -> IO ()</div><div><br></div><div>instance RelatedConst A1 where</div><div> something _ = putStrLn "hello"</div><div><br></div><div>instance RelatedConst A2 where</div><div> something _ = putStrLn "world"</div><div><br></div><div>Then, each declaration and instance could go in its own file.</div><div><br></div><div>If on the other hand, you are using lots of partial case matches everywhere, see if there are commonalities and extract a typeclass for each group</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 23, 2017 at 6:29 PM, 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-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br></div>