<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Dear Cafe,<div class=""><br class=""></div><div class="">I'm tinkering with the idea for arbitrary Haskell functions to be easily called from scripting code, I see auto derive with GHC.Generics might be the most promising tool, but I'm lost after read <a href="https://wiki.haskell.org/GHC.Generics" class="">https://wiki.haskell.org/GHC.Generics</a> and hackage docs. I have no clue so far with how to start with it.</div><div class=""><br class=""></div><div class="">Specifically I want the section highlighted in blue get auto generated, within the following `runghc` ready example:</div><div class=""><br class=""></div><div class="">```</div><div class=""><div style="color: rgb(212, 190, 152); font-family: Menlo, Monaco, "Courier New", monospace; line-height: 18px; white-space: pre;" class=""><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(155, 132, 218);" class="">{-# </span><span style="color: rgb(155, 132, 218); font-weight: bold;" class="">LANGUAGE</span><span style="color: rgb(155, 132, 218);" class=""> </span><span style="color: rgb(155, 132, 218); text-decoration: underline;" class="">BangPatterns</span><span style="color: rgb(155, 132, 218);" class=""> #-}</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">module</span><span style="color: #73a36c;" class=""> Main </span><span style="color: #cc524b;" class="">where</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Prelude</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> GHC.Generics</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Data.Dynamic</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""><br class=""></span><div class=""><span style="color: rgb(126, 107, 95); background-color: rgb(255, 255, 255);" class="">-- * minimum data structures as interface with scripting code</span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">type</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrKey</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">String</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">data</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrVal</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">NilValue</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">|</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">IntValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #6b95c5;" class="">Integer</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">|</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #6b95c5;" class="">String</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">deriving</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #6b95c5;" class="">Eq</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Ord</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Typeable</span>)</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Show</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrVal</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> show </span><span style="color: #cca143;" class="">NilValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"nil"</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> show </span>(<span style="color: #cca143;" class="">IntValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">x</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> show x</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> show </span>(<span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">x</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> show x</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">data</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">{</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">positional'args</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span>[<span style="color: #6b95c5;" class="">AttrVal</span>]</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">keyword'args</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span>[(<span style="color: #6b95c5;" class="">AttrKey</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrVal</span>)]</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">}</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Semigroup</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> p1 kw1</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> p2 kw2</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">p1 </span><span style="color: #a3d349;" class="">++</span><span style="color: #d4bfa0;" class=""> p2</span>)<span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">kw1 </span><span style="color: #a3d349;" class="">++</span><span style="color: #d4bfa0;" class=""> kw2</span>)</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Monoid</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> mempty </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span>[]<span style="color: #d4bfa0;" class=""> </span>[]</span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">class</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Callable</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;font-style: italic;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #96b946;" class=""> </span><span style="color: #66a89d;" class="">call</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;font-style: italic;" class="">a</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">ArgsPack</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span>(<span style="color: #6b95c5;" class="">AttrVal</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>())<span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>()</span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""><br class=""></span><div class=""><span style="color: rgb(126, 107, 95); background-color: rgb(255, 255, 255);" class="">-- * functions to be callable from scripting code</span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">newtype</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Assert</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Assert</span><span style="color: #d4bfa0;" class=""> </span>(</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Expect</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Maybe</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Target</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Message</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Message</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>)</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">type</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Expect</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrVal</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">type</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Target</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">AttrVal</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">type</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Message</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">String</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #cc524b;" class="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Callable</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Assert</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><br class=""></span><div class=""><span style="color: rgb(126, 107, 95); background-color: rgba(32, 90, 255, 0.239216);" class=""> -- can this get auto-generated ? with <a href="https://wiki.haskell.org/GHC.Generics" class="">https://wiki.haskell.org/GHC.Generics</a></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> call </span>(<span style="color: #cca143;" class="">Assert</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">assert</span>)<span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">args </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">kwargs</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">exit </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">expect</span>,<span style="color: #d4bfa0;" class=""> target</span>,<span style="color: #d4bfa0;" class=""> message</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> parseApk</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> result </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> assert expect target message</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> exit </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> result</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></span></div><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><br class=""></span><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #96b946;" class=""> </span><span style="color: #66a89d;" class="">parseApk</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>(<span style="color: #6b95c5;" class="">Expect</span>,<span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Maybe</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Target</span>,<span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Message</span>)</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> parseApk </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> goParse</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">Left</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"missing arg: expect"</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"missing arg: message"</span>)</span></div><div class=""><span style="color: rgb(212, 191, 160); background-color: rgba(32, 90, 255, 0.239216);" class=""> args</span></div><div class=""><span style="color: rgb(212, 191, 160); background-color: rgba(32, 90, 255, 0.239216);" class=""> kwargs</span></div><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><br class=""></span><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> </span>[]<span style="color: #d4bfa0;" class=""> </span>[]<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'expect </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left</span><span style="color: #d4bfa0;" class=""> msg </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error msg</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> expect </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'message </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left</span><span style="color: #d4bfa0;" class=""> msg </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error msg</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> message </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> return </span>(<span style="color: #d4bfa0;" class="">expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> message</span>)</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> args' </span>((<span style="color: #d4bfa0;" class="">name</span>,<span style="color: #d4bfa0;" class=""> val</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">:</span><span style="color: #d4bfa0;" class=""> kwargs'</span>)</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> name </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"expect"</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'expect </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"duplicate arg: expect"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> val</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> args' kwargs'</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"target"</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'target </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"duplicate arg: target"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> val</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> args' kwargs'</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"message"</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'message </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"duplicate arg: message"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> val </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> message </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> message</span>)<span style="color: #d4bfa0;" class=""> args' kwargs'</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"bad arg type for: message"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"unexpected keyword args"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">val </span><span style="color: #cca143;" class="">:</span><span style="color: #d4bfa0;" class=""> args'</span>)<span style="color: #d4bfa0;" class=""> </span>[]<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'expect </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> val</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> args' </span>[]</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'target </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> val</span>,<span style="color: #d4bfa0;" class=""> got'message</span>)<span style="color: #d4bfa0;" class=""> args' </span>[]</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> got'message </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Left{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> val </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> message </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> goParse </span>(<span style="color: #d4bfa0;" class="">got'expect</span>,<span style="color: #d4bfa0;" class=""> got'target</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right</span><span style="color: #d4bfa0;" class=""> message</span>)<span style="color: #d4bfa0;" class=""> args' </span>[]</span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"bad arg type for: message"</span></span></div><div class=""><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Right{}</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"extranous positional args"</span></span></div><span style="background-color: rgba(32, 90, 255, 0.239216);" class=""><br class=""></span><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="color: rgb(126, 107, 95); background-color: rgb(255, 255, 255);" class="">-- mockup & test out</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #66a89d;" class="">main</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>()</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class="">main </span><span style="color: #cc524b;font-weight: bold;" class="">=</span></span></div><div class=""><span style="color: rgb(212, 191, 160); background-color: rgb(255, 255, 255);" class=""> call</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">Assert</span><span style="color: #d4bfa0;" class=""> assert</span>)</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">ArgsPack</span><span style="color: #d4bfa0;" class=""> </span>[<span style="color: #cca143;" class="">IntValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">333</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">StrValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"as good will"</span>]</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>[(<span style="color: #97a2a7;" class="">"target"</span>,<span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">IntValue</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">333</span>)]</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span>)</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">\</span><span style="color: #d4bfa0;" class="">result </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> putStrLn </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"Got result: "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> show result</span></span></div><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span><div class=""><span style="color: rgb(126, 107, 95); background-color: rgb(255, 255, 255);" class="">-- | plain Haskell function meant to be easily called by scripting code</span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #66a89d;" class="">assert</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Expect</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Maybe</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Target</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Message</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Message</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class="">assert </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">expect </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">maybeTarget </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">message </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> maybeTarget </span><span style="color: #cc524b;" class="">of</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> return </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"* assertion not applicable: "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> message</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> target </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">if</span><span style="color: #d4bfa0;" class=""> expect </span><span style="color: #a3d349;" class="">==</span><span style="color: #d4bfa0;" class=""> target</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">then</span><span style="color: #d4bfa0;" class=""> return </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"* assertion passed: "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> message</span></span></div><div class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">else</span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"* assertion failed: "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> message</span></span></div><span style="background-color: rgb(41, 40, 40);" class=""><br class=""></span></div></div><div class="">```</div><div class=""><br class=""></div><div class="">I tried to understand how </div><ul style="margin: 0.8em 0px 0.8em 2em; padding: 0px; color: rgb(232, 230, 227); font-family: sans-serif; font-size: 13px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(24, 26, 27);" class=""><li style="margin: 0px; padding: 0px;" class="">The compiler can provide a default generic implementation for <code style="margin: 0px; padding: 0px; line-height: 16.12px;" class=""><a href="https://hackage.haskell.org/package/aeson-1.5.4.0/docs/Data-Aeson.html#v:parseJSON" title="Data.Aeson" style="margin: 0px; padding: 0px; color: rgb(179, 120, 101); text-decoration: none;" class="">parseJSON</a></code>.</li></ul><div class="">is implemented in [aeson](<a href="https://hackage.haskell.org/package/aeson" class="">https://hackage.haskell.org/package/aeson</a>) and it is overwhelming to me at the moment ...</div><div class=""><br class=""></div><div class="">Is there easier scaffold template for me to start with GHC.Generics? Or there're even better techniques to achieve my final goal?</div><div class=""><br class=""></div><div class="">Help please!</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Compl</div><div class=""><br class=""></div></body></html>