-
Notifications
You must be signed in to change notification settings - Fork 107
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
A fully-worked unqualifier example would be very helpful. #324
Comments
Wow you're really getting into the good stuff now! :) You're right, this part of the pipeline could use a fully worked example with explanation, that would have made your task much less painful (and this is a useful area so well worth reducing the pain here). There are also some unstated assumptions (maybe we could put these explicitly into types). Since you're so close, maybe I can help try to isolate the problem first? The assumption made in this unqualify process is that the expressions that come out will be fully type-annotated (they'll have a valid Having said that, I'm not sure exactly how you're getting an expression out that doesn't have type annotations (unless maybe your It might be worth having different |
Ahh, I see, I'm very sorry, but I took out another entry of the record above. The code above does work, the issue is if I try to make a record with of the form {bar:double} say. I have code to make the type as
And to make the record value
Is it that my ExprPtr for the double is not not type-annotated? If so, what's the recommended way of doing that? |
Ah ha, that's definitely a problem then. There's an overloaded function Anyway, this should work:
|
Thanks, with that and a similar incantation for the general MkArray case I now have nicely typed sql queries working. |
That sounds really interesting. Would you mind elaborating on what you're doing? I'm just curious, I like to find useful unqualifiers especially to show people who think that type classes are the whole story w.r.t. type constraints. |
So if we take postgres as an example, we can, given a query string, infer the types and column names of the returned data. Thus, at compile time we can assert that this query will return an array of records of a given type, and at run-time actually perform the query and get data of the required type. So I can say This I have working, the next step is to allow parameterised queries. Sadly it doesn't seem possible to get the required type of the query from the string, so this will have to be something like |
That is a really great idea! Very cool. For queries with unbound parameters (where you can't infer the type yet), your type signature makes sense. You have a hook in
^---- That would boil down to |
Sorry, but I could use a little advice on my bound param version.
and so, for a given unqualify, create the appropriate op, bind it to a new unique name, and return an ExprPtr of a Var of that new name.
(The "Query returned" bit comes from the custom op instance). Any idea as to why this approach doesn't work? Ah, I see, this doesn't work. If I try |
Interesting, this should be fine so you're not doing anything wrong. One small point is that you can avoid binding low-level functions (which require interfacing with LLVM) and instead add "hidden" definitions through that "Definitions" parameter to I can reproduce this independently of your unqualifier this way:
Looking at it, I think that this is just a silly bug to do with function binding introduced when moving between one of the several breaking API changes made to LLVM and I can put in a fix independent of your work. I guess in the interim (though I should have a fix soon) you can do that eta expansion to work around it:
But definitely what you're trying to do is reasonable and should be legal, my fault. |
Turns out this was an issue with global aliases to "LLFuncs" (as with your example and also this |
Sorry to spam you, one more question on your last point -- eta expansion aside, are you concerned with "when" your query runs? That may be a different issue, that you need to delay query execution. You can definitely evaluate queries at "compile time", but depending on what you want to do you might need to divide the query execution so that you can calculate the types at the first stage and then actually run the query for results at the second stage (where results must have the types you decided at the first stage). If you have questions about how to do that staging I'd be happy to elaborate, but maybe the only issue here was this LLFunc aliasing issue. |
Yes, the issue was some confusion about what was where with compile and run-time. Fixed now, thanks very much for the help. |
I've been trying to make an Unqualifier, and find myself rather stuck.
Suppose I want to be able to write
a = foo :: (Foo "bar" w) => w
and have 'a' equal to the record {bar='bar'}
I need functions TString* -> MonoTypePtr and TString* -> ExprPtr which would seem to be something like
I think I have the refine, satisfied and satisfiable logic working with the above type, the problem is with the reification of the value in unqualify. Looking at others, we dispatch based upon the type of some incoming expression. I tried copying that (with no understanding) as
This however segfaults, trying to compile an Expr with null type. So is the record construction above correct? And if so, how should I go about implementing unqualify?
The text was updated successfully, but these errors were encountered: