You can do that using the Typeable class and possibly the Dynamic type.<br>(Data.Typeable and Data.Dynamic in base)<br><br>When you have:<br><br>foo :: (Typeable a, Num a) =&gt; a -&gt; a<br>foo x = case (cast x :: Maybe Int) of<br>

    Just x&#39; -&gt; x + 12<br>    _ -&gt; x<br><br>foo will accept every instance of Num but will add 12 to it only if it is an Int.<br><br>Dynamic wraps an instance of Typeable.<br><br><div class="gmail_quote">2011/7/22 Patrick Browne <span dir="ltr">&lt;<a href="mailto:patrick.browne@dit.ie" target="_blank">patrick.browne@dit.ie</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is it possible to access type information and perform either of the<br>
following in a Haskell program?<br>
<br>
1) Find the type/class of a variable<br>
e.g. a type predicate:  is y of-type A, or is y of-Class A<br>
<br>
2) Assert the type of a variable<br>
e.g. if y.length &gt; 100 then y is of type big.<br>
<br>
Regards,<br>
Pat<br>
<br>
<br>
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. <a href="http://www.dit.ie" target="_blank">http://www.dit.ie</a><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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>
</blockquote></div><br>