<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi everybody,<div><br></div><div>I'm working on a module that encodes "static" facts about "the real world". &nbsp;For now, I'm working on an ISO 3166 compliant list of countries, country names, and country codes. &nbsp;I've run into a bit of an optimization issue.</div><div><br></div><div>There is a static bijective correspondence between countries and their codes. &nbsp;In order to keep one just one "large" data structure representation as Haskell code, I encoded this bijection using a list. &nbsp;I'm looking to write queries against this list, but it is rather tedious. &nbsp;I figured I could make some Data.Maps to handle it for me.</div><div><br></div><div><br></div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">-- Country and ISOCountryCodes derive (Data, Eq, Ord, Show, Typeable)</font></div><div><font class="Apple-style-span" face="'Courier New'">countries_and_iso_country_codes :: [ (Country, ISOCountryCode) ]</font></div><div><font class="Apple-style-span" face="'Courier New'">countries_and_iso_country_codes = &nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;[ ( Afghanistan</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , ISOCountryCode &nbsp;AF &nbsp; &nbsp; AFG</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp;(isoNumericCode 004) )</font></div><div><font class="Apple-style-span" face="'Courier New'"></font><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;, ( AlandIslands</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , ISOCountryCode &nbsp;AX</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp;ALA</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp;(isoNumericCode 248) )</font></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;, ( Albania</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , ISOCountryCode &nbsp;AL</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp;ALB</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'"> &nbsp; &nbsp;(isoNumericCode 008) )</font></div><div><font class="Apple-style-span" face="'Courier New'"></font><span class="Apple-style-span" style="font-family: 'Courier New'; ">...</span></div></div><div><font class="Apple-style-span" face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-style-span" style="white-space: pre;">, ( Zimbabwe                                   , ISOCountryCode  ZW            ZWE            (isoNumericCode 716) )
        ]</span></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="white-space: pre;"><div>map_country_to_country_code :: Map Country ISOCountryCode</div><div>map_country_to_country_code = fromList countries_and_iso_country_codes</div><div><br></div><div>map_country_code_to_country :: Map ISOCountryCode Country</div><div>map_country_code_to_country = fromList . fmap (\(a,b) -&gt; (b, a)) $ countries_and_iso_country_codes</div><div><br></div><div><font class="Apple-style-span" face="Helvetica">Is there anyway to instruct GHC (and maybe other compilers) to compute these maps statically?  Are GHC and the other compilers smart enough to do it automatically?  Although the list isn't huge, I would still rather get rid of the O(2*n) operation of turning it into maps at run-time.  (Especially since some later list encodings like these might be enormous)  What should I be looking into?</font></div><div><font class="Apple-style-span" face="Helvetica"><br></font></div><div><font class="Apple-style-span" face="Helvetica">Thanks</font></div></span></font></div></body></html>