<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-11295132.post5537671004678118594..comments</id><updated>2012-02-05T07:28:11.858-08:00</updated><category term='monad'/><category term='mathematics'/><category term='physics'/><category term='optimisation'/><category term='astronomy'/><category term='self-reference'/><category term='probability'/><category term='comonads'/><category term='haskell'/><category term='types'/><category term='programming'/><category term='quantum'/><title type='text'>Comments on A Neighborhood of Infinity: More Parsing With Best First Search</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.sigfpe.com/feeds/5537671004678118594/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11295132/5537671004678118594/comments/default'/><link rel='alternate' type='text/html' href='http://blog.sigfpe.com/2009/09/language-nomonomorphismrestrictiongener.html'/><author><name>sigfpe</name><uri>http://www.blogger.com/profile/08096190433222340957</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://homepage.mac.com/sigfpe/.Pictures/Photo%20Album%20Pictures/2002-12-07%2014.53.40%20-0800/ImageDSC01397_1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-11295132.post-3329521680146458606</id><published>2009-12-22T04:39:06.427-08:00</published><updated>2009-12-22T04:39:06.427-08:00</updated><title type='text'>I have a Haskell program for parsing and evaluatin...</title><content type='html'>I have a Haskell program for parsing and evaluating an mathematical expression of type:&lt;br /&gt;data Expr&lt;br /&gt;= Num Double&lt;br /&gt;| Add Expr Expr&lt;br /&gt;| Mul Expr Expr&lt;br /&gt;| Sin Expr&lt;br /&gt;| Cos Expr&lt;br /&gt;| Var Name&lt;br /&gt;| Neg Expr&lt;br /&gt;deriving (Eq,Show)&lt;br /&gt;&lt;br /&gt;type Name = String&lt;br /&gt;&lt;br /&gt;I have the defined a property to perform quickcheck: to check the readExpr and showExpr are valid bothway round, here readExpr takes a string of type &amp;quot;2*3+x&amp;quot; and converts it to Expression of type Expr and vice versa for showExpr&lt;br /&gt;-}&lt;br /&gt;prop_showReadExpr :: Expr -&amp;gt; Bool&lt;br /&gt;prop_showReadExpr ex = case (readExpr(showExpr ex)) of&lt;br /&gt;Nothing -&amp;gt; False&lt;br /&gt;_ -&amp;gt; showExpr(fromJust(readExpr(showExpr ex))) == showExpr ex&lt;br /&gt;&lt;br /&gt;instance Arbitrary Expr where&lt;br /&gt;arbitrary = sized arbExpr&lt;br /&gt;&lt;br /&gt;arbExpr :: Int -&amp;gt; Gen Expr&lt;br /&gt;arbExpr s =&lt;br /&gt;frequency&lt;br /&gt;[ (1, do n &amp;lt;- arbitrary return (Num (abs(n))))&lt;br /&gt;, (s, do a &amp;lt;- arbExpr s&amp;#39; b &amp;lt;- arbExpr s&amp;#39; return (Add a b))&lt;br /&gt;, (s, do a &amp;lt;- arbExpr s&amp;#39; b &amp;lt;- arbExpr s&amp;#39; return (Mul a b))&lt;br /&gt;, (s, do a &amp;lt;- arbExpr s&amp;#39; return (Sin (a)))&lt;br /&gt;, (s, do a &amp;lt;- arbExpr s&amp;#39; return (Cos (a)))&lt;br /&gt;, (1, do return (Var &amp;quot;x&amp;quot;))&lt;br /&gt;]&lt;br /&gt;where s&amp;#39; = s `div` 2&lt;br /&gt;&lt;br /&gt;Now I want to get a random expression fro my GUI Calculator, where whenever the user presses a button and the Calculator generates a random Expression of the above type.Can I use the arbExpr which returns a Expression of type &amp;#39;Gen Expr&amp;#39; for my GUI Calculator, the problem I am having is whenever I try to use :showExpr (arbExpr 9) to get an Expr I get type miss match error saying:&lt;br /&gt;Couldn&amp;#39;t match expected type `Expr&amp;#39;&lt;br /&gt;against inferred type `Gen Expr&amp;#39;&lt;br /&gt;In the first argument of `showExpr&amp;#39;, namely `(arbExpr 1)&amp;#39;&lt;br /&gt;In the expression: showExpr (arbExpr 1)&lt;br /&gt;In the definition of `it&amp;#39;: it = showExpr (arbExpr 1)&lt;br /&gt;&lt;br /&gt;Thanks in Advance..</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11295132/5537671004678118594/comments/default/3329521680146458606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11295132/5537671004678118594/comments/default/3329521680146458606'/><link rel='alternate' type='text/html' href='http://blog.sigfpe.com/2009/09/language-nomonomorphismrestrictiongener.html?showComment=1261485546427#c3329521680146458606' title=''/><author><name>pawan</name><uri>http://www.blogger.com/profile/18297382490170708374</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.sigfpe.com/2009/09/language-nomonomorphismrestrictiongener.html' ref='tag:blogger.com,1999:blog-11295132.post-5537671004678118594' source='http://www.blogger.com/feeds/11295132/posts/default/5537671004678118594' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-671660167'/></entry></feed>
