tag:blogger.com,1999:blog-11295132.post5537671004678118594..comments2024-02-24T01:46:31.188-08:00Comments on A Neighborhood of Infinity: More Parsing With Best First Searchsigfpehttp://www.blogger.com/profile/08096190433222340957noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-11295132.post-62963947699948083202014-01-09T02:01:15.018-08:002014-01-09T02:01:15.018-08:00> The minimum weight leaf is at C
C appears to...> The minimum weight leaf is at C<br /><br />C appears to be the maximum weight leaf. that doesn't seem to affect the rest of the post though.phaedrushttps://www.blogger.com/profile/06982170581581509504noreply@blogger.comtag:blogger.com,1999:blog-11295132.post-33295216801464586062009-12-22T04:39:06.427-08:002009-12-22T04:39:06.427-08:00I have a Haskell program for parsing and evaluatin...I have a Haskell program for parsing and evaluating an mathematical expression of type:<br />data Expr<br />= Num Double<br />| Add Expr Expr<br />| Mul Expr Expr<br />| Sin Expr<br />| Cos Expr<br />| Var Name<br />| Neg Expr<br />deriving (Eq,Show)<br /><br />type Name = String<br /><br />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 "2*3+x" and converts it to Expression of type Expr and vice versa for showExpr<br />-}<br />prop_showReadExpr :: Expr -> Bool<br />prop_showReadExpr ex = case (readExpr(showExpr ex)) of<br />Nothing -> False<br />_ -> showExpr(fromJust(readExpr(showExpr ex))) == showExpr ex<br /><br />instance Arbitrary Expr where<br />arbitrary = sized arbExpr<br /><br />arbExpr :: Int -> Gen Expr<br />arbExpr s =<br />frequency<br />[ (1, do n <- arbitrary return (Num (abs(n))))<br />, (s, do a <- arbExpr s' b <- arbExpr s' return (Add a b))<br />, (s, do a <- arbExpr s' b <- arbExpr s' return (Mul a b))<br />, (s, do a <- arbExpr s' return (Sin (a)))<br />, (s, do a <- arbExpr s' return (Cos (a)))<br />, (1, do return (Var "x"))<br />]<br />where s' = s `div` 2<br /><br />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 'Gen Expr' 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:<br />Couldn't match expected type `Expr'<br />against inferred type `Gen Expr'<br />In the first argument of `showExpr', namely `(arbExpr 1)'<br />In the expression: showExpr (arbExpr 1)<br />In the definition of `it': it = showExpr (arbExpr 1)<br /><br />Thanks in Advance..pawanhttps://www.blogger.com/profile/18297382490170708374noreply@blogger.com