Hi,
I’m trying to port some Haskell code using GHC.Generics to PureScript. The code should be able to apply a higher kinded data record specialized with the “Diff” type to the same record specialized with the “Identity” type, and the reverse procedure, that is calculating the diff from two records.
My Haskell code can be found here:
- the Diff type:
https://github.com/mjepronk/apie/blob/master/src/Apie/Diff/Types.hs - the GHC.Generics code:
https://github.com/mjepronk/apie/blob/master/src/Apie/Diff/GDiffable.hs - the test suite:
https://github.com/mjepronk/apie/blob/master/test/DiffSpec.hs
I’ve found there are quite some differences between GHC.Generics and purescript-generics-rep, for example PS does not seem to destructure a type recursively, for example:
data Person' f = Person
{ name :: f String
, age :: f (Maybe Int)
, languages :: f (Array String)
, available :: f Boolean
}
type Person = Person' Identity
initialPerson :: Person
initialPerson =
Person
{ name: Identity "Matthias"
, age: Identity Nothing
, languages: Identity []
, available: Identity false
}
Gives:
> :t from initialPerson
Constructor "Person"
(Argument
{ age :: Identity (Maybe Int)
, available :: Identity Boolean
, languages :: Identity (Array String)
, name :: Identity String
}
)
The types contained in the record are not converted to a Generic representation. Should I use RowToList
instead of Generics?
Is there any example code for PS Generics Rep out there? I’ve read Harry’s blog post on the topic, but it does not help me much with my more complicated use case: notably the HKD type, and the fact that I want to return the original type (not a String serialization).
Any help is greatly appreciated!