Questions tagged [generics-sop]

The `generics-sop` Haskell library

https://hackage.haskell.org/package/generics-sop

See pedagogic resources here.

8 questions
6
votes
2 answers

Deriving projection functions using `generics-sop`

How would I go about deriving the function getField :: (Generic a, HasDatatypeInfo a) => Proxy (name :: Symbol) -> a -> b to project a field from an arbitrary record using a type-level string (Symbol), using the generics-sop library? This is…
5
votes
1 answer

Generic isomorphism between sums and heterogeneous sums

Is there a Haskell library providing (or assisting in writing) generic isomorphism between a sum type and an associated heterogenous sum type? Take the following sum type, data TR = TR_Index | TR_Inner R Now we associate it with a heterogenous sum…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
5
votes
1 answer

Creating a sum constructor value using `generics-sop`

In generics-sop, what is the idiomatic way to generically create a sum constructor value given both its position (index) and the product value of its args? For example consider, -- This can be any arbitrary type. data Prop = Name String | Age Int |…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
5
votes
1 answer

Super classes with All from generics-sop

I'm trying to use All from generics-sop to constrain a list of types. Everything works as expected with simple classes like All Typeable xs, but I'd like to be able to do something like the following: class (Typeable a) => TestClass (a ::…
matchwood
  • 257
  • 1
  • 7
3
votes
1 answer

Generically iterating over accessors of a product type

I've written the following function using generics-sop. What it does, is given a value of a product type, goes through all it's members, applies a function to all those members, and spits out a list of the results: import Generics.SOP qualified as…
Clinton
  • 22,361
  • 15
  • 67
  • 163
2
votes
1 answer

Case-matching on `NS` type

The NS type from sop-core creates an interesting conundrum. In S :: NS f xs -> NS f (x ': xs) where xs ~ '[] means that the argument to the S is inhabited. Yet Haskell's case matching forces me to match on it. Is there a resolution to this…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
1
vote
1 answer

Using `generics-sop` to get type metadata info at compile time

I've been using generics-sop quite successfully so far, but for one use case I'd like to get the names of record fields. The types I'm working with are product types, and I can use the constraint IsProductType a xs to enforce this. Doing so I end up…
Clinton
  • 22,361
  • 15
  • 67
  • 163
1
vote
2 answers

Reifying types with generics-sop metadata

I would like to produce a rose tree representation (called Header in the following) of a data type using generics-sop, but I got stuck at one detail; specifically, how to pass type information "one level down" within the implementation of mkAnonProd…
ocramz
  • 816
  • 6
  • 18