makeFields on a type family - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

James King

I've forgotten the syntax to quote the type of a type family and it's bloody hard to find the right keywords to search for it... but you have a product type family like:

data family Person (version :: Nat)

data instance Person 0 = PersonV0 { _personName :: String, _personAge :: Int }
data instance Person 1 = PersonV1 { _personName :: String, _personAge :: Int, _personFriends :: [Person 1] }

I get a parse error with:

makeFields ''(Person 0) -- bad
makeFields ''Person 0 -- bad

I recall there is a way to quote the type but I can't recall what it is and I'm having trouble finding it. Anyone happen to know?

James King

Does it work on the value constructor?

makeFields 'PersonV0

Seems to compile at least... :thinking:

James King

I think that is the key. Seems to work as expected.

If you need to generate lenses for a data family instance this seems to be the way to go.

James King

Except that you will end up generating multiple lenses for the same field across type family instances so it may be a no go... but that's a different problem.