beam icon indicating copy to clipboard operation
beam copied to clipboard

Type error trying to delete all rows in a table after upgrading to GHC 9.0.2 from GHC 8.10.7

Open jerbaroo opened this issue 3 years ago • 0 comments

EDIT: The error and relevant code are shown below, however I will highlight the (hopefully) temporary workaround which I am using:

  (const $ Beam.val_ True) -- CHANGED THIS
  (\row -> UD.userID row /=. Beam.val_ "__HELP-THE-TYPE-CHECKER__") -- TO THIS

The code in question:

-- | Delete all unverified user details.
unsafeDeleteAll :: RunTx m => m ()
unsafeDeleteAll = Db.runDelete $ Beam.delete
  (S.unverifiedUserDetailsTable S.userAccountServiceDb)
  (const $ Beam.val_ True)

And here is the error:

src/Uas/Db/UnverifiedUserDetails.hs:87:4: error:
    • Couldn't match type ‘b0’
                     with ‘forall s'.
                           UD.UnverifiedUserDetailsT
                             (Beam.QExpr
                                beam-postgres-0.5.1.0:Database.Beam.Postgres.Types.Postgres s')’
      Expected: (forall s'.
                 UD.UnverifiedUserDetailsT
                   (Beam.QExpr
                      beam-postgres-0.5.1.0:Database.Beam.Postgres.Types.Postgres s'))
                -> Beam.QExpr
                     beam-postgres-0.5.1.0:Database.Beam.Postgres.Types.Postgres s Bool
        Actual: b0
                -> Beam.QExpr
                     beam-postgres-0.5.1.0:Database.Beam.Postgres.Types.Postgres s Bool
      Cannot instantiate unification variable ‘b0’
      with a type involving polytypes:
        forall s'.
        UD.UnverifiedUserDetailsT
          (Beam.QExpr
             beam-postgres-0.5.1.0:Database.Beam.Postgres.Types.Postgres s')
    • In the second argument of ‘Beam.delete’, namely
        ‘(const $ Beam.val_ True)’
      In the second argument of ‘($)’, namely
        ‘Beam.delete
           (S.unverifiedUserDetailsTable S.userAccountServiceDb)
           (const $ Beam.val_ True)’
      In the expression:
        Db.runDelete
          $ Beam.delete
              (S.unverifiedUserDetailsTable S.userAccountServiceDb)
              (const $ Beam.val_ True)
   |
87 |   (const $ Beam.val_ True)
   |    ^^^^^^^^^^^^^^^^^^^^^^

RunTx and Db.runDelete are defined by us. I tried again after removing them. The slightly different code and error:

-- | Delete all unverified user details.
unsafeDeleteAll = Beam.runDelete $ Beam.delete
  (S.unverifiedUserDetailsTable S.userAccountServiceDb)
  (const $ Beam.val_ True)

src/Uas/Db/UnverifiedUserDetails.hs:84:19: error:
    • Ambiguous type variable ‘be0’ arising from a use of ‘Beam.runDelete’
      prevents the constraint ‘(Database.Beam.Backend.SQL.BeamSqlBackend
                                  be0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘be0’ should be.
      These potential instances exist:
        two instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘($)’, namely ‘Beam.runDelete’
      In the expression:
        Beam.runDelete
          $ Beam.delete
              (S.unverifiedUserDetailsTable S.userAccountServiceDb)
              (const $ Beam.val_ True)
      In an equation for ‘unsafeDeleteAll’:
          unsafeDeleteAll
            = Beam.runDelete
                $ Beam.delete
                    (S.unverifiedUserDetailsTable S.userAccountServiceDb)
                    (const $ Beam.val_ True)
   |
84 | unsafeDeleteAll = Beam.runDelete $ Beam.delete
   |                   ^^^^^^^^^^^^^^

jerbaroo avatar Aug 04 '22 23:08 jerbaroo