Compare commits
2 commits
5113241a63
...
c85e2ffecd
Author | SHA1 | Date | |
---|---|---|---|
c85e2ffecd | |||
e338e3a738 |
2 changed files with 35 additions and 1 deletions
|
@ -5,11 +5,17 @@ import Expr
|
||||||
import Parser
|
import Parser
|
||||||
|
|
||||||
data Law = Law LawName Equation
|
data Law = Law LawName Equation
|
||||||
deriving Show
|
|
||||||
|
|
||||||
type LawName = String
|
type LawName = String
|
||||||
type Equation = (Expr,Expr)
|
type Equation = (Expr,Expr)
|
||||||
|
|
||||||
|
instance Show Law where
|
||||||
|
showsPrec _ (Law name (e1, e2)) =
|
||||||
|
showString (name ++ ": ")
|
||||||
|
. shows e1
|
||||||
|
. showString " = "
|
||||||
|
. shows e2
|
||||||
|
|
||||||
law :: Parser Law
|
law :: Parser Law
|
||||||
law = do name <- upto ':'
|
law = do name <- upto ':'
|
||||||
eqn <- equation
|
eqn <- equation
|
||||||
|
@ -20,3 +26,21 @@ equation = do lh <- expr
|
||||||
symbol "="
|
symbol "="
|
||||||
rh <- expr
|
rh <- expr
|
||||||
return (lh, rh)
|
return (lh, rh)
|
||||||
|
|
||||||
|
sortLaws :: [Law] -> [Law]
|
||||||
|
sortLaws laws = simple ++ others ++ defn
|
||||||
|
where (simple, nonsimple) = partition isSimple laws
|
||||||
|
(defn, others) = partition isDefn nonsimple
|
||||||
|
|
||||||
|
isSimple, isDefn :: Law -> Bool
|
||||||
|
|
||||||
|
isSimple (Law _ (Compose a, Compose b))
|
||||||
|
= length a > length b
|
||||||
|
|
||||||
|
isDefn d = case d of
|
||||||
|
(Law _ (Compose [Con f es], _)) -> all Calculator.isVar es
|
||||||
|
_ -> False
|
||||||
|
|
||||||
|
isVar v = case v of
|
||||||
|
(Compose [Var _]) -> True
|
||||||
|
_ -> False
|
||||||
|
|
10
Utils.hs
10
Utils.hs
|
@ -3,3 +3,13 @@ module Utils where
|
||||||
|
|
||||||
symbolic = (`elem` symbolic_ops)
|
symbolic = (`elem` symbolic_ops)
|
||||||
symbolic_ops = "!@#$%^&*+./<=>?\\^|:-~"
|
symbolic_ops = "!@#$%^&*+./<=>?\\^|:-~"
|
||||||
|
|
||||||
|
-- doing 'partition f xs = (filter f xs, filter (not . f) xs)' is too
|
||||||
|
-- slow, cuz it would run same test twice on every paramter. I might
|
||||||
|
-- be wrong tho
|
||||||
|
partition :: (a -> Bool) -> [a] -> ([a], [a])
|
||||||
|
partition _ [] = ([], [])
|
||||||
|
partition f (x:xs)
|
||||||
|
| f x = (x:pass, fail)
|
||||||
|
| otherwise = (pass, x:fail)
|
||||||
|
where (pass, fail) = partition f xs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue