Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comprehensions without a generator do not desugar #8

Open
jstolarek opened this issue Apr 10, 2017 · 0 comments
Open

Comprehensions without a generator do not desugar #8

jstolarek opened this issue Apr 10, 2017 · 0 comments

Comments

@jstolarek
Copy link

Say I have a table containing agencies:

data Agency = Agency
    { a_id       :: Integer
    , a_name     :: Text
    , a_based_in :: Text
    , a_phone    :: Text
    } deriving (Show)

agencies :: Q [Agency]
agencies = table "agencies"
                 ( "a_id" :|
                 [ "a_name"
                 , "a_based_in"
                 , "a_phone"
                 ])
                 (TableHints (pure $ Key (pure "a_id") ) NonEmpty)

And I write a query that looks like this:

q2 :: Q [Text]
q2 = [ z
     | a <- agencies
     , z <- [ a_nameQ a | a_nameQ a == "EdinTours" ]
     ]

This is a well-formed query and it executes correctly. However, trying to desugar it via showDesugaredOptQ optResugar q2 leads to:

DSH: Impossible happened at ("src/Database/DSH/Translate/CL2NKL.hs",288,37)
CallStack (from HasCallStack):
  error, called at src/Database/DSH/Translate/CL2NKL.hs:288:37 in DSH-0.13.0.1-EuPUolq064bCwy8rK7h5w4:Database.DSH.Translate.CL2NKL

The problem lies in the definition of desuagrQuals that expects that every comprehension will eventually contain a BindQ qualifier - clearly not the case for a comprehension containing only a GuardQ.

I know that q2 might look a bit contrived but I've actually been hit by this issue in my work on provenance, where queries get transformed to a form that does not contain a generator, just guards.

@jstolarek jstolarek changed the title Comprehensiond without a generator do not desugar Comprehensions without a generator do not desugar Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant