readExpr :: String -> Maybe Expr readExpr s = case expr modS of Just (a,_) -> Just a _ -> Nothing where modS = filter (/= ' ') s
module ExprQC where import Test.QuickCheck import Expr prop_ShowReadExpr :: Expr -> Bool prop_ShowReadExpr expr = readExpr (show expr) == Just (assoc expr) assoc :: Expr -> Expr assoc (Add (Add a b) c) = assoc (Add a (Add b c)) assoc (Add a b) = Add (assoc a) (assoc b) assoc (Mul (Mul a b) c) = assoc (Mul a (Mul b c)) assoc (Mul a b) = Mul (assoc a) (assoc b) assoc (Sin a) = Sin (assoc a) assoc (Cos a) = Cos (assoc a) assoc a = a
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help [1 of 2] Compiling Expr ( Expr.hs, interpreted ) [2 of 2] Compiling ExprQC ( ExprQC.hs, interpreted ) Ok, modules loaded: ExprQC, Expr. *ExprQC> quickCheck prop_ShowReadExpr *** Failed! Falsifiable (after 1 test): Num 0.0
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106