[Haskell-cafe] Is it possible to get the selector functions when defining a generic class?

chris at kahn.pro chris at kahn.pro
Thu Nov 24 02:52:14 UTC 2016


Hey all!

I'm trying to understand what's going on in GHC.Generics and defining a 
generic class... I understand that there's a `Selector` class and `selName` 
function that can get the *name* of a selector, but is there a way to 
access the selector function itself? The documentation conveniently avoids 
examples involving records and is otherwise quite barren.

So if I have a data type like...

data Person = Person
    { name :: String
    , age :: Int
    } deriving Generic

instance MyTypeClass Person

I want my generic implementation of MyTypeClass to be able to access each 
selector function in the record, f :: Person -> String, g :: Person -> Int, 
etc.

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161123/53c64c7e/attachment.html>


More information about the Haskell-Cafe mailing list