valderman / selda

A type-safe, high-level SQL library for Haskell
https://selda.link
MIT License
478 stars 58 forks source link

Cannot derive instances of SqlType #13

Open dmjio opened 7 years ago

dmjio commented 7 years ago

Inference fails when using GeneralizedNewTypeDeriving w/ SqlType. StandaloneDeriving is similar.

newtype TodoId = TodoId { unTodoId :: Int }
  deriving (Show, Eq, FromJSON, ToJSON, SqlType) 
 Main.hs:62:41-47: error: …  
    • Couldn't match type ‘Int’ with ‘TodoId’
        arising from the coercion of the method ‘mkLit’
          from type ‘Int -> Lit Int’ to type ‘TodoId -> Lit TodoId’ 
    • When deriving the instance for (SqlType TodoId)
valderman commented 7 years ago

That's one error I've never seen before. Looks like GADTs only play semi-well with newtype deriving. It might be possible to restructure the Lit type to fix it...

valderman commented 7 years ago

As of 0.1.8.0, SqlType instances can be created manually when importing Database.Selda.Backend. Still no solution deriving instances, however.

valderman commented 6 years ago

I don't believe the current SqlType API will ever be able to support automatic derivation. If someone comes up with a better one I wouldn't mind merging it, but since instances can now be created manually with relative ease, I think we should let this stay on the backburner for now.