<div dir="auto">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><div class="gmail_quote">On Feb 12, 2018 3:58 PM, "Vilem-Benjamin Liepelt" <<a href="mailto:vl81@kent.ac.uk">vl81@kent.ac.uk</a>> wrote:<br type="attribution"><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>
<br>
The type-foo looks very cool and I will have to dig more into the different options.<br>
<br>
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>
<br>
Unfortunately It's not really viable to use this "for real" at the moment because it requires such an old version of GHC.<br>
<br>
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>
<br>
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>
<br>
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>
<br>
I will definitely check out the other suggestions as well though, thank you again.<br>
<br>
Best,<br>
<br>
Vilem<br>
<br>
> On 2018-02-12, at 09:08, Frerich Raabe <<a href="mailto:raabe@froglogic.com">raabe@froglogic.com</a>> wrote:<br>
><br>
> On 2018-02-12 03:30, Vilem-Benjamin Liepelt wrote:<br>
>> I am looking for a solution to get rid of this silly boilerplate:<br>
>> eval :: Ord var => Map var Bool -> Proposition var -> Bool<br>
>> eval ctx prop = evalP $ fmap (ctx Map.!) prop<br>
>>  where<br>
>>    evalP = \case<br>
>>        Var b -> b<br>
>>        Not q -> not $ evalP q<br>
>>        And p q -> evalP p && evalP q<br>
>>        Or p q -> evalP p || evalP q<br>
>>        If p q -> evalP p ==> evalP q<br>
>>        Iff p q -> evalP p == evalP q<br>
><br>
> [..]<br>
><br>
> You might benefit from the 'catamorphism' package:<br>
><br>
>  <a href="https://hackage.haskell.org/package/catamorphism-0.5.1.0/docs/Data-Morphism-Cata.html" rel="noreferrer" target="_blank">https://hackage.haskell.org/<wbr>package/catamorphism-0.5.1.0/<wbr>docs/Data-Morphism-Cata.html</a><br>
><br>
> It provides a template Haskell function which, given a data type, produces a function which reduces (folds) that data type.<br>
><br>
> --<br>
> Frerich Raabe - <a href="mailto:raabe@froglogic.com">raabe@froglogic.com</a><br>
> <a href="http://www.froglogic.com" rel="noreferrer" target="_blank">www.froglogic.com</a> - Multi-Platform GUI Testing<br>
<br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div>