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.

This package contains the generics system described in the Scrap Your Boilerplate papers (see http://www.cs.uu.nl/wiki/GenericProgramming/SYB).

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.

http://hackage.haskell.org/package/syb

39 questions
73
votes
4 answers

What is Haskell's Data.Typeable?

I've come across references to Haskell's Data.Typeable, but it's not clear to me why I would want to use it in my code. What problem does it solve, and how?
Muin
  • 1,251
  • 11
  • 8
28
votes
4 answers

Boilerplate-free annotation of ASTs in Haskell?

I've been fiddling around with the Elm compiler, which is written in Haskell. I'd like to start implementing some optimizations for it, and part of this involves traversing the AST and adding "annotation" to certain nodes, such as tail-calls, etc. I…
18
votes
1 answer

What is "Scrap Your Boilerplate"?

I see people talking about Scrap Your Boilerplate and generic programming in Haskell. What do these terms mean? When would I want to use Scrap Your Boilerplate, and how do I use it?
16
votes
1 answer

Understanding the type signature of gfoldl from Data.Data.Data

Data defines as one of its core functions gfoldl: gfoldl :: (Data a) => (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> a -> c a What's the purpose of c and c (d -> b) in it? Why isn't it just a regular…
Petr
  • 62,528
  • 13
  • 153
  • 317
11
votes
2 answers

Clojure equivalent of Haskell's "Scrap Your Boilerplate" (SYB)

I found an interesting library in Haskell called Scrap Your Boilerplate based on a paper by Simon Peyton Jones which seems like an effective way to write code that can update large, deeply nested data structures in a functional programming language.…
mikera
  • 105,238
  • 25
  • 256
  • 415
11
votes
1 answer

Scrap Your Boilerplate in f#

I've used the Scrap Your Boilerplate and Uniplate libraries in the Haskell programming language, and I would find that form of generic programming over discriminated unions to be really useful. Is there an equivalent library in the f# programming…
9
votes
1 answer

Deriving default instances using GHC.Generics

I have a typeclass Cyclic for which I would like to be able to provide generic instances. class Cyclic g where gen :: g rot :: g -> g ord :: g -> Int Given a sum type of nullary constructors, data T3 = A | B | C deriving (Generic,…
cdk
  • 6,698
  • 24
  • 51
9
votes
2 answers

How to construct generic Functor instances using GHC.Generics (or other similar frameworks)?

I'm trying to learn GHC Generics. After reviewing several examples, I wanted to try to create a generic Functor instances (disregarding that GHC can derive them automatically for me). However, I realized I have no idea how to work with a…
Petr
  • 62,528
  • 13
  • 153
  • 317
9
votes
2 answers

Relationship between TypeRep and "Type" GADT

In Scrap your boilerplate reloaded, the authors describe a new presentation of Scrap Your Boilerplate, which is supposed to be equivalent to the original. However, one difference is that they assume a finite, closed set of "base" types, encoded with…
Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
8
votes
1 answer

Advantages of SYB (scrap your boilerplate) over GHC Generics

Are any tasks that are possible only with SYB, or are much easier with it, when compared to GHC Generics?
Petr
  • 62,528
  • 13
  • 153
  • 317
6
votes
3 answers

Generic programming in Haskell with SYB and ad-hoc polymorphism

I have a class identical to Show and I would like to make an instance of this class for each tuple type. Usually this is done by writing separately instances for each tuple type instance (Show a, Show b) => Show (a,b) where showsPrec _ (a,b) s =…
mariop
  • 3,195
  • 1
  • 19
  • 29
5
votes
1 answer

Is it possible to use SYB to transform the type?

I want to write a rename function to replace String names (which represent hierarchical identifiers) in my AST with GUID names (integers) from a symbol table carried as hidden state in a Renamer monad. I have an AST a type that is parameterized over…
pat
  • 12,587
  • 1
  • 23
  • 52
5
votes
2 answers

Haskell's Scrap Your Boilerplate (SYB) - applying transformation only once instead of everywhere

What's the best way to apply a transformation to a tree only once instead of everywhere using SYB? For instance, in the following simplified expression, there are several instances of Var "x", and I want to replace the first instance with Var "y"…
5
votes
1 answer

How to define SYB functions for type extension for tertiary type constructors (ext3)?

In the Scrap Your Boilerplate package, in Data.Generics.Aliases, there are functions to allow type extension for unary, and binary type constructors. In particular, there are definitions for ext1 and ext2. Now, ext1 and ext2 are defined in terms of…
scvalex
  • 14,931
  • 2
  • 34
  • 43
4
votes
2 answers

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 -> c a The only functions I can think of are \xs y -> ($y) <$> xs and…
Dannyu NDos
  • 2,458
  • 13
  • 32
1
2 3