Are any tasks that are possible only with SYB, or are much easier with it, when compared to GHC Generics?
GHC Generics is a rather verbose way to perform basically any query or traversal. For example, consider a language AST with Stmt
and Expr
types that both derive Typeable
, Generic
, and Data
:
data Stmt = ... lots of constrs ...
data Expr = Const Int
| ... lots of other constrs ...
How do you leverage SYB to get all constants starting from either Expr
or Stmt
? Something like:
getConst (Const i) = [i]
getConst _ = []
getAllConst = everything (++) (mkQ getConst)
Contrast this with the typical use of Generics requiring two classes, a traversal over the sum of products representation, and instantiate the class N times for the N types needing traversed. Where SYB, and indeed most generic systems, fall flat is in performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With