markhibberd/riak-haskell-client — pull request #7 by Davorak (2014-05-09 00:08:36+00:00)
Title: Fix double commit issue with Resolveable puts. Replace resolveMany' with resolveMany.

Values are `resolved` twice for every resolvable `put`. This means that if you put a value `a` then what ends up in Riak is `resolve a a`. This is fine for structures like sets but not so much for other structures.

On reading the documentation I thought the following behavior was described:
put bucket key a
-- `a` is now stored in Riak under the bucket key pair bucket, key
put bucket key a1
-- `resolve a a1` is now stored in Riak under the bucket key pair bucket, key

The committed files give the above behavior for the small number of by hand tests I have preformed. If this is the preferred behavior I will try and come up with some monadic QuickCheck code to test it.

Here is a code snippet that produces this issue with the current version of the riak package.

newtype SingularJSON a = SingularJSON { getSingularJSON :: [a] }
deriving (Show, Generic)

deriving instance (FromJSON a) => FromJSON (SingularJSON a)
deriving instance (ToJSON a) => ToJSON (SingularJSON a)

instance (Resolvable a) => Resolvable (SingularJSON a) where
resolve (SingularJSON [a]) (SingularJSON [b]) = SingularJSON $ [resolve a b]

type SingularSum a = SingularJSON (ResolvableMonoid (Sum a))

> let a = SingularJSON . (\x -> [x]) . RM . Sum $ (1::Int)
> withConnection pool $ \conn -> RJ.put conn "test" "test Nothing (a :: SingularSum Int) Default Default
-- report bacck value of SingularJSON {getSingularJSON = [RM {unRM = Sum {getSum = 2}}]