Now there'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"><<a href="mailto:cetin.sert@gmail.com">cetin.sert@gmail.com</a>></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;"> 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 ⇒ Out a where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 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;"> {-# SPECIALISE out :: String $B"*(B String #-}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 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;"> {-# SPECIALISE out :: Char $B"*(B String #-}</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 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 <<, $B"c(B</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">($B"c(B), (<<) :: Out a ⇒ IO Handle $B"*(B a $B"*(B IO Handle</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(<<)= ($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;"> s $B"+(B h</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> hPutStr s $ out a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 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 = 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 = "\n"</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> :? 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> cout << 22 << False </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">22False{handle: <stdout>}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Prelude IOStream> cout << 22 << False << endl</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><interactive>:1:0:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Overlapping instances for Out String</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> arising from a use of `<<' at <interactive>:1:0-26</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Matching instances:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> instance (Show a) => Out a -- Defined in IOStream</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> instance Out String -- Defined in IOStream</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> In the expression: cout << 22 << False << endl</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> In the definition of `it': it = cout << 22 << False << 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>