on master help sign in
Fix incorrect >>= implementation for Query (#73)
commit70ce05d8d16dea32521c32a8a2c2f5211c39a972 authorShane <shane.obrien@circuithub.com> dateTue 22 Jun 2021, 23:01 (5 years ago) parentf36d7d0
1 file changed+10−5
src/Rel8/Query.hs+10−5
src/Rel8/Query.hs+10−5
@@ -174,7 +174,7 @@ instance Monad Query where
174174 Opaleye.QueryArr qa = q dummies
175175 ((m, a), query', tag') = qa ((), query, tag)
176176 Query q' = f a
177− (dummies', lquery, tag'') =
177+ (dummies', query'', tag'') =
178178 ( dummy : dummies
179179 , Opaleye.Rebind True bindings query'
180180 , Opaleye.next tag'
@@ -185,11 +185,16 @@ instance Monad Query where
185185 random = Opaleye.FunExpr "random" []
186186 name = Opaleye.extractAttr "dummy" tag'
187187 Opaleye.QueryArr qa' = Opaleye.lateral $ \_ -> q' dummies'
188− ((m'@(Any needsDummies), b), rquery, tag''') = qa' ((), Opaleye.Unit, tag'')
189− lquery'
190− | needsDummies = lquery
188+ -- NOTE: query''' and needsDummies are corecursive; only laziness saves
189+ -- us here.
190+ --
191+ -- This refactoring, if adopted, would allow us to do this without
192+ -- relying on laziness:
193+ -- https://github.com/tomjaguarpaw/haskell-opaleye/commit/8a23f5028ab7396290984d63a8316949909fdbb4
194+ ((m'@(Any needsDummies), b), query'''', tag''') = qa' ((), query''', tag'')
195+ query'''
196+ | needsDummies = query''
191197 | otherwise = query'
192− query'''' = Opaleye.times lquery' rquery
193198 m'' = m <> m'
194199 in
195200 ((m'', b), query'''', tag''')