<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi David,<div class=""><br class=""></div><div class="">I don't think this is well-typed. GHC seems to infer `Proposition a -> Bool -> Bool` (by majority vote?) but obviously then complains about the cases `id` and `not`.</div><div class=""><br class=""></div><div class="">I believe that there is a way to do this with dependent types, but not sure whether this is possible in Haskell.</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">Vilem</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 2018-02-15, at 13:51, David Fox <<a href="mailto:dsf@seereason.com" class="">dsf@seereason.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div dir="ltr" class=""><div class="gmail_default" style="font-size:small">You actually can pattern match on constructor only:</div><div class="gmail_default" style="font-size:small"><br class=""></div><div class="gmail_default" style="font-size:small"><div class="gmail_default">magic = \case</div><div class="gmail_default">    Var {} -> id</div><div class="gmail_default">    Not  {}-> not</div><div class="gmail_default">    And {} -> (&&)</div><div class="gmail_default">    Or {} -> (||)</div><div class="gmail_default">    If {} -> (==>)</div><div class="gmail_default">    Iff {} -> (==)</div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Feb 11, 2018 at 6:30 PM, Vilem-Benjamin Liepelt <span dir="ltr" class=""><<a href="mailto:vl81@kent.ac.uk" target="_blank" class="">vl81@kent.ac.uk</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I am looking for a solution to get rid of this silly boilerplate:</div><div class=""><br class=""></div><div class=""><div style="font-family:Menlo" class="">eval :: Ord var => Map var Bool -> Proposition var -> Bool</div><div style="font-family:Menlo" class="">eval ctx prop = evalP $ fmap (ctx Map.!) prop</div><div style="font-family:Menlo" class="">  where</div><div style="font-family:Menlo" class="">    evalP = \case</div><div style="font-family:Menlo" class="">        Var b -> b</div><div style="font-family:Menlo" class="">        Not q -> not $ evalP q</div><div style="font-family:Menlo" class="">        And p q -> evalP p && evalP q</div><div style="font-family:Menlo" class="">        Or p q -> evalP p || evalP q</div><div style="font-family:Menlo" class="">        If p q -> evalP p ==> evalP q</div><div style="font-family:Menlo" class="">        Iff p q -> evalP p == evalP q</div></div><div style="font-family:Menlo" class=""><br class=""></div><div class="">What I would like to do in essence is to replace the data constructors like so:</div></div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><div class=""><div class="">-- Not valid Haskell!! Can't pattern match on constructor only...</div><div class="">magic = \case</div><div class="">    Var -> id</div><div class="">    Not -> not</div><div class="">    And -> (&&)</div><div class="">    Or -> (||)</div><div class="">    If -> (==>)</div><div class="">    Iff -> (==)</div></div><div class=""><br class=""></div><div class=""><div class="">compile = transformAST magic $ fmap (\case 'P' -> False; 'Q' -> True)</div><div class=""><br class=""></div><div class="">>>> compile (Iff (Not (And (Var 'P') (Var 'Q'))) (Or (Not (Var 'P')) (Not (Var 'Q'))))</div><div class="">            ((==) (not ((&&) (id True) (id False))) ((||) (not (id True)) (not (id False))))</div></div><div class=""><br class=""></div></font></div><div class="">Note how the compiled expression exactly mirrors the AST, so there should be some meta programming technique for this.</div><div class=""><br class=""></div><div class="">Does anyone have an idea how I can achieve this?</div><div class=""><br class=""></div><div class="">The full source code is here: <a href="https://gist.github.com/vimuel/7dcb8a9f1d2b7b72f020d66ec4157d7b" target="_blank" class="">https://gist.github.com/<wbr class="">vimuel/<wbr class="">7dcb8a9f1d2b7b72f020d66ec4157d<wbr class="">7b</a></div><div class=""><br class=""></div><div class="">I am happy to take any other comments relating to my code...</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">Vilem</div></div><br class="">______________________________<wbr class="">_________________<br class="">
Haskell-Cafe mailing list<br class="">
To (un)subscribe, modify options or view archives go to:<br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
Only members subscribed via the mailman list are allowed to post.<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>