Specialize inline is its own pragma. Read <a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html?highlight=specialize#specialize-pragma">https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html?highlight=specialize#specialize-pragma</a><div><br></div><div><br><div><br></div><div><br></div><div><br>On Friday, June 17, 2016, Jyotirmoy Bhattacharya <<a href="mailto:jyotirmoy@jyotirmoy.net">jyotirmoy@jyotirmoy.net</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Thanks! I could not find the SPECIALIZABLE pragma in the docs. Can you please give me a pointer. As to inline, while it would work, there might be a large cost in code size, if say the `insert` function of a hash table were to be inlined everywhere it is used in a program. <br><br></div>Regards,<br></div>Jyotirmoy<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 17, 2016 at 9:15 PM, Carter Schonwald <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','carter.schonwald@gmail.com');" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You probably want specializable and specialize inline pragmas. <div><div><span></span><br><br>On Friday, June 17, 2016, Jyotirmoy Bhattacharya <<a href="javascript:_e(%7B%7D,'cvml','jyotirmoy@jyotirmoy.net');" target="_blank">jyotirmoy@jyotirmoy.net</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sorry, realized that attachments cannot be sent to the list. I have put the code on GitHub here <a href="https://github.com/jmoy/testing-specialize" target="_blank">https://github.com/jmoy/testing-specialize</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 17, 2016 at 4:31 PM, Jyotirmoy Bhattacharya <span dir="ltr"><<a>jyotirmoy@jyotirmoy.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>I'm trying to write a mutable hash table library that would work both in the IO and ST monads, so I'm using the PrimMonad typeclass [see JmoyHash.hs in the attached archive]. <br><br></div>For efficiency, I would like the functions to be specialized to the concrete monad at the call site. According to <a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#specialize-for-imported-functions" target="_blank">Section 9.31.9.2 of the GHC User's Guide</a><br><br><div style="margin-left:40px">The optimiser <em>also</em> considers each <em>imported</em> <tt><span>INLINABLE</span></tt>
overloaded function, and specialises it for the different types at which
it is called in <tt><span>M</span></tt>. <br><br></div>So I marked all the functions in my library as INLINABLE. Yet adding a SPECIALIZE pragma in Main.hs (currently commented out) for an imported function improves runtime performance by 3x, which should not be happening since, if I understand the manual right, the function should have been specialized anyway since it is marked INLINABLE.<br><br></div>I am writing to this list rather than filing a bug since I'm not sure if I'm reading the manual right and I have not explicitly verified that the specialization is not happening. I would greatly appreciate any help on both counts.<br><br></div>I'm using GHC 8.0.1 with the -O2 flag.<br><br></div>Marking the function as INLINE might solve the problem but that's something I don't want to do as it seems to me that specialization and not inlining is what's appropriate here.<br><br></div>Regards,<br></div>Jyotirmoy Bhattacharya<br></div>
</blockquote></div><br></div>
</blockquote>
</div></div></blockquote></div><br></div>
</blockquote></div></div>