As a school project i am going to create a graphic calculator. The following code comes from two files, Expr.hs and ExprQC.hs.
From Expr.hs
readExpr :: String -> Maybe Expr
readExpr s =
case expr modS of
Just (a,"") -> Just a
_ -> Nothing
where
modS = filter (/= ' ') s
From ExprQC.hs
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
I get the error on GHCi
Prelude> :l ExprQC.hs
[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
How can I fix this?
Edit: This is what GHCi returns after inputting the respective expression.
*ExprQC> readExpr (show (Num 0.0))
Nothing
And
*ExprQC> Just (assoc (Num 0.0))
Just (Num 0.0)
Thank you.