Questions tagged [scrap-your-boilerplate]
This Haskell package contains the generics system described in the Scrap Your Boilerplate papers. It defines the Data class of types permitting folding and unfolding of constructor applications, instances of this class for primitive types, and a variety of traversals.
scrap-your-boilerplate
39
questions
1
vote
2
answers
66
views
SYB `mkT` function in Scala
Continuing on from a previous question of mine, I am attempting to implement Scrap Your Boilerplate in scala 3 and am running into an issue now with the mkT function described in the paper. Given the ...
0
votes
1
answer
58
views
SYB `cast` function in Scala
I am reading the Scrap Your Boilerplate paper and trying to follow along by implementing the ideas in scala as best I can. However, I'm stuck on the very first function, the cast, which is used to ...
0
votes
2
answers
111
views
Haskell syb Data.Generics not working as expected
On a ghci prompt everywhere (mkT (\x -> 2 * x)) (8.7, 21, "word") evaluates to (8.7, 42, "word").
I expected the 8.7 to be doubled as well. Why am I wrong?
2
votes
1
answer
105
views
Matching higher-kinded types in SYB
In general, I'm wondering if there's a way to write a generic fold that generalizes a function that applies a forall type like:
f :: forall a. Data (D a) => D a -> b
given some datatype D for ...
4
votes
2
answers
511
views
How to use Data.Data?
As I'm not familiar with rank-N types, the type signature of gfoldl is a troublesome for me:
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> a
...
1
vote
4
answers
130
views
A function for returning part of a product or record depending on parameter and requested return type
I'm looking for a function, that, given the necessary return type, will return the part of a product parameter that matches that type, based purely on the structure of the type passed to the function.
...
3
votes
2
answers
102
views
Traversing polymorphic structures and performing a transformation only in few cases
Suppose we represent a company hierarchy in the following way:
{-# LANGUAGE DeriveDataTypeable #-}
import Data.Data
import Data.Generics.Aliases
import Data.Generics....
2
votes
0
answers
121
views
Scrapping the boilerplate of doing variable substitution in an expression
Suppose we have the following data structure, whose values represent expressions on some language:
data BExpr = Stop
| Guard Expr BExpr
| Choice BExpr BExpr
| ...
0
votes
2
answers
195
views
How to fold over a constructor with special cases?
So I have a tree that I want to collapse where the nodes are of type
data Node = Node1 Node | Node2 Node Node | ... deriving Data
except for a few special cases. I want to do something along the ...
4
votes
1
answer
484
views
Recursive Type Lensing
I'm trying to create some code that can take any recursive grammar data type and any expression of that data type and produce a list of all sub-expressions of the same type, built up, kind of like a ...
2
votes
0
answers
124
views
How to traverse a Seq with the Scrap Your Boileplate combinator "everything" in Shapeless?
I want to use the Scrap Your Boilerplate implementation in Shapeless to operate on some case classes but i'm stuck trying to figure out how to make the SYB combinator everything traverse a field of ...
1
vote
1
answer
68
views
SYB Libraries functions
I've been working with some scrap-your-boilerplate functions for a while. Nevertheless, I tried to compile a module that imports Data.Data and Data.Typeable, though some functions like everywhere and ...
1
vote
1
answer
105
views
Understanding Constr type of Data.Data package of Haskell
I am trying to understand the Constr type of Data.Data package. Consider the session below. dataTypeConstrs returns a list of Constr, both zero- and one-argument constructors of Maybe. Attempting to ...
2
votes
1
answer
558
views
Visiting GHC AST with SYB
I wrote a program that visited the AST with Haskell-src-exts. I'm trying to convert it to use the GHC API. The former uses Uniplate, while for the latter it seems that unfortunately I'm forced with ...
3
votes
2
answers
219
views
SYB: can a map over the result of listify be rewritten with a gfoldl?
Can I use SYB's gfoldl to do the map over the result of listify in one go?
Consider for example the following code:
extractNums :: Expr -> [Int]
extractNums e = map numVal $ listify isNum e
...