Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with generic deriving for non-flat records #133

Open
MangoIV opened this issue Aug 30, 2023 · 0 comments
Open

How to deal with generic deriving for non-flat records #133

MangoIV opened this issue Aug 30, 2023 · 0 comments

Comments

@MangoIV
Copy link

MangoIV commented Aug 30, 2023

Hi, I wonder whether there is some preferred, idiomatic way to deal with things like

data A = MkA 
  { a1 :: Text 
  , a2 :: B 
  } 
  deriving stock Generic 
  deriving anyclass FromForm 

data B = MkB 
  { b1 :: Text 
  , ... }
  deriving stock Generic 
  deriving anyclass FromForm 

fails with "No instance FromHttpApiData B arising from..." because of this instance her:

instance {-# OVERLAPPABLE #-} (Selector s, FromHttpApiData c) => GFromForm t (M1 S s (K1 i c)) where
  gFromForm _ opts form = M1 . K1 <$> parseUnique key form
    where
      key = Text.pack $ fieldLabelModifier opts $ selName (Proxy3 :: Proxy3 s g p)

This is quite unfortunate because I would like to somehow indicate that this should be derived recursively somehow; perhaps we can indicate this somehow by using a newtype wrapper in A's recursive field and then deriving everything newtype for it and then add an {-# OVERLAPPING #-} instance to the generic deriving? Though that would be quite the mess. I wonder what is a good way to do this.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant