Now there&#39;s also a stackoverflow question for this:<br><a href="http://stackoverflow.com/questions/955711/specialization-in-type-classes-using-ghc">http://stackoverflow.com/questions/955711/specialization-in-type-classes-using-ghc</a><br>

Any help highly appreciated!<br><br><div class="gmail_quote">2009/6/5 Cetin Sert <span dir="ltr">&lt;<a href="mailto:cetin.sert@gmail.com">cetin.sert@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<span style="font-family: courier new,monospace;">module IOStream where</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import System.IO</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">import System.IO.Unsafe</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class Out a where</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp; out :: a $B"*(B String</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Show a &rArr; Out a where</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp; out = show</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Out String where</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp; {-# SPECIALISE out :: String $B"*(B String #-}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; out = id</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance Out Char where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; {-# SPECIALISE out :: Char $B"*(B String #-}</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp; out = \x $B"*(B [x]</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">infixl 0 &lt;&lt;, $B"c(B</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">($B"c(B), (&lt;&lt;) :: Out a &rArr; IO Handle $B"*(B a $B"*(B IO Handle</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(&lt;&lt;)= ($B"c(B)</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">h $B"c(B a = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; s $B"+(B h</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp; hPutStr s $ out a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; return s</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cout, cin, cerr :: IO Handle</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cout = return stdout</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">cin&nbsp; = return stdin</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cerr = return stderr</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">endl :: String</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">endl = &quot;\n&quot;</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">---</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cetin@unique:~/lab/c/linking/demo$ ghci -fglasgow-exts iostream.hs</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">GHCi, version 6.10.2: <a href="http://www.haskell.org/ghc/" target="_blank">http://www.haskell.org/ghc/</a>&nbsp; :? for help</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">Loading package ghc-prim ... linking ... done.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Loading package integer ... linking ... done.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Loading package base ... linking ... done.</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">Ok, modules loaded: IOStream.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Prelude IOStream&gt; cout &lt;&lt; 22 &lt;&lt; False </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">22False{handle: &lt;stdout&gt;}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Prelude IOStream&gt; cout &lt;&lt; 22 &lt;&lt; False &lt;&lt; endl</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&lt;interactive&gt;:1:0:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Overlapping instances for Out String</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `&lt;&lt;&#39; at &lt;interactive&gt;:1:0-26</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; Matching instances:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instance (Show a) =&gt; Out a -- Defined in IOStream</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instance Out String -- Defined in IOStream</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; In the expression: cout &lt;&lt; 22 &lt;&lt; False &lt;&lt; endl</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; In the definition of `it&#39;: it = cout &lt;&lt; 22 &lt;&lt; False &lt;&lt; endl</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">o________________O</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">how can I specialise a type class function?</span><br style="font-family: courier new,monospace;">


</blockquote></div><br>