<div dir="ltr">Why not just use a datastructure with 6 Bools?  E.g.:<div><br></div><div>data SixDots = SixDots</div><div>  { dot1 :: Bool</div><div>  , dot2 :: Bool</div><div>  , dot3 :: Bool</div><div>  , dot4 :: Bool</div><div>  , dot5 :: Bool</div><div>  , dot6 :: Bool</div><div>  }<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">There may be even better ways to do this, but I would consider something like this if I were working on this problem.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Although I do end up using TH sometimes, I usually find that it is better to use non-meta-level solutions when practical.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Best,</div><div class="gmail_extra">Ryan</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 28, 2016 at 9:06 AM, Mario Lang <span dir="ltr"><<a href="mailto:mlang@delysid.org" target="_blank">mlang@delysid.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi.<br>
<br>
As a long-term Lisp fan, and someone who always admired compile-time<br>
code-generation, I wanted to at least do something simple with Template<br>
Haskell once.<br>
<br>
In a small project of mine, I have this basically auto-generated data<br>
type:<br>
<br>
-- Braille music code only uses the old 6-dot system.  We enumerate all<br>
-- possible dot patterns to use the type system to avoid accidentally<br>
-- specifying invalid dot patterns in the source code.<br>
--<br>
-- gen :: String<br>
-- gen =<br>
--     "data Braille = " ++ intercalate " | " ctors ++ " deriving (Enum, Eq)" where<br>
--   ctors = "NoDots" : map ctorName [1..63] where<br>
--     ctorName :: Int -> String<br>
--     ctorName = (++) "Dot" . concatMap (show . succ) . flip filter [0..5] . testBit<br>
<br>
data SixDots = NoDots | Dot1 | Dot2 | Dot12 | Dot3 | Dot13 | Dot23 | Dot123<br>
             | Dot4 | Dot14 | Dot24 | Dot124 | Dot34 | Dot134 | Dot234<br>
             | Dot1234 | Dot5 | Dot15 | Dot25 | Dot125 | Dot35 | Dot135<br>
             | Dot235 | Dot1235 | Dot45 | Dot145 | Dot245 | Dot1245 | Dot345<br>
             | Dot1345 | Dot2345 | Dot12345 | Dot6 | Dot16 | Dot26 | Dot126<br>
             | Dot36 | Dot136 | Dot236 | Dot1236 | Dot46 | Dot146 | Dot246<br>
             | Dot1246 | Dot346 | Dot1346 | Dot2346 | Dot12346 | Dot56 | Dot156<br>
             | Dot256 | Dot1256 | Dot356 | Dot1356 | Dot2356 | Dot12356<br>
             | Dot456 | Dot1456 | Dot2456 | Dot12456 | Dot3456 | Dot13456<br>
             | Dot23456 | Dot123456<br>
             deriving (Bounded, Enum, Eq, Read, Show)<br>
<br>
So, while actually quite simple, this looks like an opportunity to use<br>
Template Haskell for me.  In other words, I want to figure out what is<br>
necessary to generate this data type with TH, instead of the gen<br>
function that basically generates a piece of plain Haskell code.<br>
<br>
I have been reading "A practical Template Haskell Tutorial"[1] but I find<br>
it a little bit too terse to actually solve this very little riddle on<br>
my own.<br>
<br>
For one, I find it confusing that some TH functions return "Q Dec" while<br>
others just return Dec.  I am aware that this is some sort of Monad for<br>
the TH system, but I have never seen it explained anywhere.<br>
<br>
Also, all the examples I can find seem to be mostly focused in<br>
generating Q Exp or similar, but I didn't really find an example<br>
for Q Dec.<br>
<br>
I realize this should be simple to figure out on my own, but it<br>
apparently is not.  I have tried to wrap my head around this on my own<br>
at least three times now, but always stopped after an hour or two due to<br>
frustration.  Is there some comprehensive TH documentation I haven't<br>
seen yet?  Could you please give me enough of a head-start that I<br>
actually manage to write something which can generate this simple data<br>
type above?<br>
<br>
[1] <a href="https://wiki.haskell.org/A_practical_Template_Haskell_Tutorial" rel="noreferrer" target="_blank">https://wiki.haskell.org/A_<wbr>practical_Template_Haskell_<wbr>Tutorial</a><br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
CYa,<br>
  ⡍⠁⠗⠊⠕<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</font></span></blockquote></div><br></div></div>