<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><!--[if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]--></head><body><div class="ydp4ec804a0yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div>Yes, you can use IntMap. It needs another dependency and the complexity choice as <i>O(log (min (n, W)))</i> where W is a number of bits in a representing key, used for mapping. <br></div><div dir="ltr" data-setdir="false"><div><div dir="ltr">For me, it is rather hard to solve whether it can be better, because it raises another problem of efficient binary representation of the keys.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">While working on the topic, I found out that may be the most efficient will be hashing (for lookup it can be used e. g. Cuckoo hashing) and there is a library in Haskell for it.</div><div dir="ltr"><a shape="rect" class="ydp7eec1b35yiv1322360768enhancr_card_9728930781" href="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html" style="color: rgb(25, 106, 212); text-decoration-line: underline;" rel="nofollow" target="_blank">Data.HashTable.IO</a> </div><div dir="ltr">Using it, you can write something like:</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><div>{-# LANGUAGE ScopedTypeVariables #-}</div><div><br clear="none"></div><div>module Main where</div><div><br clear="none"></div><div>import qualified Data.HashTable.IO as I<br clear="none"></div><div>import Data.Maybe (fromJust,isJust)<br clear="none"></div><div>import System.Environment (getArgs)</div><div><br clear="none"></div><div>main :: IO ()<br clear="none"></div><div>main = do </div><div>         args <- getArgs</div><div>         let a = [([z,t],x) | x <- ['a'..'d'], z <- ['f'..'t'], t <- ['a'..'p'], [x,z,t] <= "fnf"] </div><div>         b :: I.CuckooHashTable String Char <- I.fromList a </div><div>         c <- I.lookup b ("kn") </div><div>         let d1 u = do </div><div>                  d <- I.lookup b u</div><div>                  print c</div><div>                  if isJust d </div><div>                    then putStrLn . show . fromJust $ d </div><div>                    else putStrLn "Nothing"</div><div>                  return () </div><div>         if null args </div><div>           then d1 "fa"</div><div>           else d1 (head $ args)</div></div><br clear="none" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br clear="none"></div><div class="ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-link-enhancr-card ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-link-enhancr-not-allow-cover ydp7eec1b35yiv1322360768ydp5578d2f1ymail-preserve-class ydp7eec1b35yiv1322360768ydp5578d2f1ymail-preserve-style" id="ydp7eec1b35yiv1322360768ydp5578d2f1enhancr_card_9728930781" data-url="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html" data-type="YENHANCER" data-size="MEDIUM" style="font-size: 16px; max-width: 400px; font-family: Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif; position: relative;"><a shape="rect" class="ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-enhancr-cardlink" href="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html" style="color: rgb(0, 0, 0) !important;" rel="nofollow" target="_blank"><table class="ydp7eec1b35yiv1322360768ydp5578d2f1card-wrapper ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" style="max-width: 400px;"><tbody><tr><td colspan="1" rowspan="1" width="400"><table class="ydp7eec1b35yiv1322360768ydp5578d2f1card ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 400px; border-width: 1px; border-style: solid; border-color: rgb(224, 228, 233); border-radius: 2px;"><tbody><tr><td colspan="1" rowspan="1"><table class="ydp7eec1b35yiv1322360768ydp5578d2f1card-info ydp7eec1b35yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; position: relative; z-index: 2; width: 398px; max-width: 400px; border-radius: 0px 0px 2px 2px; border-top: 1px solid rgb(224, 228, 233);"><tbody><tr><td colspan="1" rowspan="1" style="padding: 16px 0px 16px 12px; vertical-align: top; border-radius: 0px 0px 0px 2px;"></td><td colspan="1" rowspan="1" style="vertical-align: middle; padding: 12px 24px 16px 12px; width: 350px; border-radius: 0px 0px 2px;"><h2 class="ydp7eec1b35yiv1322360768ydp5578d2f1card-title" style="font-size: 14px; line-height: 19px; margin: 0px 0px 6px; color: rgb(38, 40, 42);">Data.HashTable.IO</h2><p class="ydp7eec1b35yiv1322360768ydp5578d2f1card-description" style="font-size: 12px; line-height: 16px; margin: 0px; color: rgb(151, 155, 167);"></p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></a><div class="ydp7eec1b35card-controls-injection-wrapper" style="width: 400px; z-index: 3; min-height: 0px;"><div class="ydp7eec1b35p_a ydp7eec1b35T_6Fd5 ydp7eec1b35R_6Fd5"><div class="ydp7eec1b35I_ak5mD ydp7eec1b35e_dRA ydp7eec1b35j_2kgqsw ydp7eec1b35P_wpoVE" style="z-index: 3;"><div data-test-id="shareButtonAnchor" class="ydp7eec1b35P_Z1otACY ydp7eec1b35H_6Fd5 ydp7eec1b35W_6Fd5"><button tabindex="-1" class="ydp7eec1b35c27KHO0_n ydp7eec1b35b_0 ydp7eec1b35M_0 ydp7eec1b35i_0 ydp7eec1b35I_T ydp7eec1b35y_Z2uhb3X ydp7eec1b35A_6EqO ydp7eec1b35r_P ydp7eec1b35C_q ydp7eec1b35cvhIH6_T ydp7eec1b35ir3_1JO2M7 ydp7eec1b35P_0" data-test-id="icon-btn-share_social" title="Поділитися"><span class="ydp7eec1b35D_F ydp7eec1b35ab_C ydp7eec1b35gl_C ydp7eec1b35W_6D6F" style="width: 16px;"></span></button></div></div></div></div></div><div style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br clear="none"></div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">so it works. And the library documentation says that a complexity of Cuckoo hash lookup is about <i>O(1)</i>, but with hashing there are questions of ratio of fulfilling the buckets and collisions.</div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br clear="none"></div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">So, my library having the very generic constraints can be used instead.</div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;"><br clear="none"></div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">Best regards,</div><div dir="ltr" style="font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 16px;">Oleksandr Zhabenko.</div><div><br></div></div></div><br></div>
        
        </div><div id="yahoo_quoted_0076557603" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    субота, 21 вересня 2019 р., 21:52:18 GMT+3, olexandr543@yahoo.com <olexandr543@yahoo.com> написав:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="yiv1322360768"><div><div class="yiv1322360768ydpdd3139d4yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr">Yes, you can. It needs another dependency and the complexity choice as <i>O(log (min (n, W)))</i> where W is a number of bits in a representing key, used for mapping. </div><div dir="ltr">For me, it is rather hard to solve whether it can be better, because it raises another problem of efficient binary representation of the keys.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">While working on the topic, I found out that may be the most efficient will be hashing (for lookup it can be used e. g. Cuckoo hashing) and there is a library in Haskell for it.</div><div dir="ltr"><span><a rel="nofollow" shape="rect" class="yiv1322360768enhancr_card_9728930781" target="_blank" href="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html">Data.HashTable.IO</a> </span></div><div dir="ltr">Using it, you can write something like:</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><div><div>{-# LANGUAGE ScopedTypeVariables #-}</div><div><br clear="none"></div><div>module Main where</div><div><br clear="none"></div><div>import qualified Data.HashTable.IO as I<br clear="none"></div><div>import Data.Maybe (fromJust,isJust)<br clear="none"></div><div>import System.Environment (getArgs)</div><div><br clear="none"></div><div>main :: IO ()<br clear="none"></div><div>main = do </div><div>         args <- getArgs</div><div>         let a = [([z,t],x) | x <- ['a'..'d'], z <- ['f'..'t'], t <- ['a'..'p'], [x,z,t] <= "fnf"] </div><div>         b :: I.CuckooHashTable String Char <- I.fromList a </div><div>         c <- I.lookup b ("kn") </div><div>         let d1 u = do </div><div>                  d <- I.lookup b u</div><div>                  print c</div><div>                  if isJust d </div><div>                    then putStrLn . show . fromJust $ d </div><div>                    else putStrLn "Nothing"</div><div>                  return () </div><div>         if null args </div><div>           then d1 "fa"</div><div>           else d1 (head $ args)</div></div><br clear="none"><div><br clear="none"></div><div class="yiv1322360768ydp5578d2f1yahoo-link-enhancr-card yiv1322360768ydp5578d2f1yahoo-link-enhancr-not-allow-cover yiv1322360768ydp5578d2f1ymail-preserve-class yiv1322360768ydp5578d2f1ymail-preserve-style" id="yiv1322360768ydp5578d2f1enhancr_card_9728930781" style="max-width:400px;font-family:Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif;" data-url="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html" data-type="YENHANCER" data-size="MEDIUM"><a rel="nofollow" shape="rect" class="yiv1322360768ydp5578d2f1yahoo-enhancr-cardlink" target="_blank" href="http://hackage.haskell.org/package/hashtables-1.2.3.4/docs/Data-HashTable-IO.html" style="text-decoration:none !important;color:#000 !important;"><table class="yiv1322360768ydp5578d2f1card-wrapper yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" style="max-width:400px;"><tbody><tr><td colspan="1" rowspan="1" width="400"><table class="yiv1322360768ydp5578d2f1card yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:400px;border-width:1px;border-style:solid;border-color:rgb(224, 228, 233);border-radius:2px;"><tbody><tr><td colspan="1" rowspan="1"><table class="yiv1322360768ydp5578d2f1card-info yiv1322360768ydp5578d2f1yahoo-ignore-table" border="0" cellpadding="0" cellspacing="0" style="background:#fff;position:relative;z-index:2;width:100%;max-width:400px;border-radius:0 0 2px 2px;border-top:1px solid rgb(224, 228, 233);"><tbody><tr><td colspan="1" rowspan="1" style="background-color:#ffffff;padding:16px 0 16px 12px;vertical-align:top;border-radius:0 0 0 2px;"></td><td colspan="1" rowspan="1" style="vertical-align:middle;padding:12px 24px 16px 12px;width:99%;font-family:Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif;border-radius:0 0 2px 0;"><h2 class="yiv1322360768ydp5578d2f1card-title" style="font-size:14px;line-height:19px;margin:0px 0px 6px;font-family:Helvetica Neue, Segoe UI, Helvetica, Arial, sans-serif;color:rgb(38, 40, 42);">Data.HashTable.IO</h2><p class="yiv1322360768ydp5578d2f1card-description" style="font-size:12px;line-height:16px;margin:0px;color:rgb(151, 155, 167);"></p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></a></div><div><br clear="none"></div><div dir="ltr">so it works. And the library documentation says that a complexity of Cuckoo hash lookup is about <i>O(1)</i>, but with hashing there are questions of ratio of fulfilling the buckets and collisions.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">So, my library having the very generic constraints can be used instead.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Best regards,</div><div dir="ltr">Oleksandr Zhabenko.</div><div dir="ltr"><br clear="none"></div><br clear="none"></div><div><br clear="none"></div>
        
        </div><div class="yiv1322360768yahoo_quoted" id="yiv1322360768yahoo_quoted_9164113538">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    субота, 21 вересня 2019 р., 21:34:38 GMT+3, Henning Thielemann <lemming@henning-thielemann.de> написав:
                </div>
                <div><br clear="none"></div>
                <div><br clear="none"></div>
                <div class="yiv1322360768yqt8700735078" id="yiv1322360768yqt58886"><div><div dir="ltr"><div class="yiv1322360768yqt0903812254" id="yiv1322360768yqtfd74755"><br clear="none">On Sat, 21 Sep 2019, olexandr543--- via Haskell wrote:<br clear="none"><br clear="none">> My library that can help to optimize using 'case ... of ...' construction if there are multiple (more than at<br clear="none">> least 5) variants.<br clear="none">> mm2: The library that can be used for optimization of multiple (Ord a) => a -> b transformations</div><br clear="none"><br clear="none">Isn't this a problem you would solve using Data.Map?<div class="yiv1322360768yqt0903812254" id="yiv1322360768yqtfd10236"><br clear="none"></div></div></div></div>
            </div>
        </div></div></div></div>
            </div>
        </div></body></html>