Hi,I am looking for a solution to get rid of this silly boilerplate:eval :: Ord var => Map var Bool -> Proposition var -> Booleval ctx prop = evalP $ fmap (ctx Map.!) propwhereevalP = \caseVar b -> bNot q -> not $ evalP qAnd p q -> evalP p && evalP qOr p q -> evalP p || evalP qIf p q -> evalP p ==> evalP qIff p q -> evalP p == evalP qWhat I would like to do in essence is to replace the data constructors like so:-- Not valid Haskell!! Can't pattern match on constructor only...magic = \caseVar -> idNot -> notAnd -> (&&)Or -> (||)If -> (==>)Iff -> (==)compile = transformAST magic $ fmap (\case 'P' -> False; 'Q' -> True)>>> compile (Iff (Not (And (Var 'P') (Var 'Q'))) (Or (Not (Var 'P')) (Not (Var 'Q'))))((==) (not ((&&) (id True) (id False))) ((||) (not (id True)) (not (id False))))Note how the compiled expression exactly mirrors the AST, so there should be some meta programming technique for this.Does anyone have an idea how I can achieve this?The full source code is here: https://gist.github.com/vimuel/ 7dcb8a9f1d2b7b72f020d66ec4157d 7b I am happy to take any other comments relating to my code...Best,Vilem
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell- cafe
Only members subscribed via the mailman list are allowed to post.