We have a couple use cases in Yesod that can potentially match many different patterns. Routing connects the url of an http request to a Haskell function. The current code just uses a pattern match, which scales linearly. So if a site has a hundred different routes (urls), it could take 100 comparisons to finally match the url to a function. Michael Snoyman is writing some code to make this issue obsolete. One of the things it does is use a Map lookup instead of a case match.<div>

<br></div><div>More worrying is our system for internationalization of a website. A user is supposed to make a sum type with every custom message as a constructor in that sum type.</div><div><br></div><div><div>data Msg = Model</div>

<div>         | Year</div><div>         | Please</div><div><br></div><div>-- Rendering function for English.</div><div>renderEnglish Model  = &quot;Model&quot;</div><div>renderEnglish Year   = &quot;Year&quot;</div><div>
renderEnglish Please = &quot;Please fill in your car&#39;s details&quot;</div>
<div><br></div><div>-- Rendering function for Swedish.</div><div>renderSwedish Model  = &quot;Modell&quot;</div><div>renderSwedish Year   = &quot;Årgång&quot;</div><div>renderSwedish Please = &quot;Vänligen fyll i uppgifterna för din bil&quot;</div>

</div><div><br></div><div>So if there are 100 custom messages on a site, that will setup a case match with potentially 100 comparisons.</div><div><br></div><div>Note that we are using this technique for type safety- switching to a map here would be difficult. We want to know at compile time that a translation exists for every message.</div>

<div><br></div><div>So first of all I am wondering if a sum type comparison does in fact scale linearly or if there are optimizations in place to make the lookup constant or logarithmic. Second, I as wondering (for the routing case) if Haskell can make a string case comparison logarithmic so that users can use case comparisons instead of maps for string collections that are known at compile time and won&#39;t change.</div>