Aside from Neil's point about rank-2 polymorphism, you can of course just parameterise your NumHolder type...<div><br></div><div>data Num a => NumHolder a = NumHolder a</div><div><br></div><div>instance Show a => Show NumHolder a where</div>
<div> show (NumHolder x) = show x</div><div><br></div><div>instance Functor NumHolder where</div><div> fmap f (NumHolder a) = NumHolder (f a)</div><div><br></div><div>It depends what you want to do with your NumHolder though. What is the purpose of this type?</div>
<div><br></div><div>Bob<br><br><div class="gmail_quote">On Fri, Jan 22, 2010 at 11:31 AM, Ozgur Akgun <span dir="ltr"><<a href="mailto:ozgurakgun@gmail.com">ozgurakgun@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Dear Cafe,<br><br>I can write and use the following,<br><br><span style="font-family:courier new,monospace">data IntHolder = IntHolder Integer</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">instance Show IntHolder where</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> show (IntHolder n) = show n</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">liftInt :: (Integer -> Integer) -> IntHolder -> IntHolder</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">liftInt f (IntHolder c) = IntHolder (f c)</span><br>
<br>But I cannot generalise it to <i>Num:</i><br><br><span style="font-family:courier new,monospace">data NumHolder = forall a. Num a => NumHolder a</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">instance Show NumHolder where</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> show (NumHolder n) = show n</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">liftNum :: (Num a) => (a -> a) -> NumHolder -> NumHolder</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">liftNum f (NumHolder c) = NumHolder (f c)</span><br><br>The error message I get is the following:<br><br><span style="font-family:courier new,monospace"> Couldn't match expected type `a' against inferred type `a1'</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> `a' is a rigid type variable bound by</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> the type signature for `liftNum' at Lifts.hs:54:16</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> `a1' is a rigid type variable bound by</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> the constructor `NumHolder' at Lifts.hs:55:11</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> In the first argument of `f', namely `c'</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> In the first argument of `NumHolder', namely `(f c)'</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> In the expression: NumHolder (f c)</span><br><br><br>Regards,<br><br clear="all"><br>-- <br><font color="#888888">Ozgur Akgun<br>
</font><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>