Are any tasks that are possible only with SYB, or are much easier with it, when compared to GHC Generics?
Asked
Active
Viewed 535 times
1 Answers
3
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.

Thomas M. DuBuisson
- 64,245
- 7
- 109
- 166