Strange behavior Database.persist -=. combinator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell, TypeFamilies, FlexibleContexts, GADTs, GeneralizedNewtypeDeriving #-}

import Database.Persist
import Database.Persist.TH
import Database.Persist.Postgresql
import Control.Monad
import Control.Monad.IO.Class
import Data.Text
import Data.Maybe

share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistLowerCase|
Account
    balance Double
    deriving Show
|]

connection :: ConnectionString
connection = "host=localhost dbname=test user=test password=test port=5432"

main = withPostgresqlPool connection 10 $ \ pool ->
    flip runSqlPersistMPool pool $ do
        runMigrationSilent migrateTables

        testAccountId <- insert $ Account 0.0

        let value = -3.0

        --This substracts 3 from the current balance:
        update testAccountId [AccountBalance +=. value]

         --This should revert the earlier change, but it doesn't:
        update testAccountId [AccountBalance -=. value]
        
        --This alternative should also revert the earlier change, and it does:
        --update testAccountId [AccountBalance +=. -value]

        account <- get testAccountId

        liftIO $ print account --Balance should have value 0.