[Haskell-cafe] Static computation/inlining

Alexander Solla ajs at 2piix.com
Sun Oct 10 21:51:59 EDT 2010

Hi everybody,

I'm working on a module that encodes "static" facts about "the real  
world".  For now, I'm working on an ISO 3166 compliant list of  
countries, country names, and country codes.  I've run into a bit of  
an optimization issue.

There is a static bijective correspondence between countries and their  
codes.  In order to keep one just one "large" data structure  
representation as Haskell code, I encoded this bijection using a  
list.  I'm looking to write queries against this list, but it is  
rather tedious.  I figured I could make some Data.Maps to handle it  
for me.

-- Country and ISOCountryCodes derive (Data, Eq, Ord, Show, Typeable)
countries_and_iso_country_codes :: [ (Country, ISOCountryCode) ]
countries_and_iso_country_codes =

         [ ( Afghanistan	                           , ISOCountryCode   
AF     AFG	    (isoNumericCode 004) )
         , ( AlandIslands	                   , ISOCountryCode  AX	     
ALA	    (isoNumericCode 248) )
         , ( Albania	                           , ISOCountryCode   
AL	    ALB	    (isoNumericCode 008) )
         , ( Zimbabwe	                           , ISOCountryCode   
ZW	    ZWE	    (isoNumericCode 716) )

map_country_to_country_code :: Map Country ISOCountryCode
map_country_to_country_code = fromList countries_and_iso_country_codes

map_country_code_to_country :: Map ISOCountryCode Country
map_country_code_to_country = fromList . fmap (\(a,b) -> (b, a)) $  

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101010/7ab7d6c7/attachment.html

More information about the Haskell-Cafe mailing list