<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Oh, indeed I wasn't aware of this. That's great news—thank you, Frerich!<div class=""><br class=""></div><div class="">This actually leads me to another question: what are the tradeoffs between implementing this via Template Haskell as in the case of this package vs the `deriving` mechanism as for the foldable instance?</div><div class=""><br class=""></div><div class="">V<br class=""><div class=""><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 2018-02-13, at 00:03, Theodore Lief Gannon <<a href="mailto:tanuki@gmail.com" class="">tanuki@gmail.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="auto" class="">Vilem, you may have missed the post from the catamorphisms author where he updated the library in response to this thread? :)</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Feb 12, 2018 3:58 PM, "Vilem-Benjamin Liepelt" <<a href="mailto:vl81@kent.ac.uk" class="">vl81@kent.ac.uk</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for your great suggestions.<br class="">
<br class="">
The type-foo looks very cool and I will have to dig more into the different options.<br class="">
<br class="">
Generating a catamorphism using the library of the same name works like a charm and integrates well with my existing code—once I managed to get it to install (thank you Stack LTS!) it just worked out of the box and let me write a one-line evaluator and a one-line pretty-printer. Woohoo!<br class="">
<br class="">
Unfortunately It's not really viable to use this "for real" at the moment because it requires such an old version of GHC.<br class="">
<br class="">
Something I miss is the clear correspondence between data constructors and "substitutions" (like in my `magic` example), since they become entirely positional, leading to potentially brittle code (imagine reordering the data constructors). I think some of the other solutions might be better in this respect.<br class="">
<br class="">
It's a shame that the catamorphism package doesn't work for a more up-to-date version of GHC, because I think I would use this quite often.<br class="">
<br class="">
I suppose the fold that Sergey proposed is essentially what the catamorphism package generates. Although I want to avoid having to write functions by hand when really the computer should be doing them for me, I think I will use this for now as it integrates nicely with my existing code and leads to quite idiomatic Haskell.<br class="">
<br class="">
I will definitely check out the other suggestions as well though, thank you again.<br class="">
<br class="">
Best,<br class="">
<br class="">
Vilem<br class="">
<br class="">
> On 2018-02-12, at 09:08, Frerich Raabe <<a href="mailto:raabe@froglogic.com" class="">raabe@froglogic.com</a>> wrote:<br class="">
><br class="">
> On 2018-02-12 03:30, Vilem-Benjamin Liepelt wrote:<br class="">
>> I am looking for a solution to get rid of this silly boilerplate:<br class="">
>> eval :: Ord var => Map var Bool -> Proposition var -> Bool<br class="">
>> eval ctx prop = evalP $ fmap (ctx Map.!) prop<br class="">
>> where<br class="">
>> evalP = \case<br class="">
>> Var b -> b<br class="">
>> Not q -> not $ evalP q<br class="">
>> And p q -> evalP p && evalP q<br class="">
>> Or p q -> evalP p || evalP q<br class="">
>> If p q -> evalP p ==> evalP q<br class="">
>> Iff p q -> evalP p == evalP q<br class="">
><br class="">
> [..]<br class="">
><br class="">
> You might benefit from the 'catamorphism' package:<br class="">
><br class="">
> <a href="https://hackage.haskell.org/package/catamorphism-0.5.1.0/docs/Data-Morphism-Cata.html" rel="noreferrer" target="_blank" class="">https://hackage.haskell.org/<wbr class="">package/catamorphism-0.5.1.0/<wbr class="">docs/Data-Morphism-Cata.html</a><br class="">
><br class="">
> It provides a template Haskell function which, given a data type, produces a function which reduces (folds) that data type.<br class="">
><br class="">
> --<br class="">
> Frerich Raabe - <a href="mailto:raabe@froglogic.com" class="">raabe@froglogic.com</a><br class="">
> <a href="http://www.froglogic.com/" rel="noreferrer" target="_blank" class="">www.froglogic.com</a> - Multi-Platform GUI Testing<br class="">
<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.</blockquote></div></div>
</div></blockquote></div><br class=""></div></div></div></div></body></html>