-
Notifications
You must be signed in to change notification settings - Fork 6
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
Exception when trying to run compile-time code: substVarsWith: couldn't look up variable substitution #8
Comments
Hi @oofp could you provide an example datatype that this produces this error? Thanks! |
I know at least some of the time that error will happen when you provide a type for which the instances don't quite make sense, but it could also be a bug, so it's quite important what your type is. Perhaps we could figure out a better error message to provide. |
Thanks @cgibbard and @ali-abrar , I am attaching minimized version of data types (with just few constructors). Please let me know if you want me to try to remove some dependency, so you can actually try to compile it in your environment. |
Hey, could you try this again with the latest version? There is at least some chance that it will work now, given that we now support data constructors with type class constraints on them (at all). However, there's still a very strong chance that it won't deal with the functional dependencies correctly, but I can't tell. |
Hello,
|
Hi again,
It compiles with ReturnAErr commented, but when I uncomment this lines I get:
|
I wonder if this is the same issue: -- | View operations for `PropertyGraph`
data PropertyGraphView v vp ep r where
PropertyGraphView_All :: PropertyGraphView v vp ep (PropertyGraph vp ep v)
PropertyGraphView_GetVertexProperty :: GCompare vp => v -> vp a -> PropertyGraphView v vp ep (Maybe a)
PropertyGraphView_GetEdgeProperty :: GCompare ep => v -> v -> ep a -> PropertyGraphView v vp ep (Maybe a) The last two constructors fail (due to
|
For |
Similarly, there is no evidence that |
@3noch Shouldn't this library automatically add those constraints in the JSON instances it generates? Adding them, instead, to the GADT constructors actually has no effect on the substVarsWith error. |
Also I'm forced to use |
@srid In your constructor there is an implicit EDIT: Well actually |
I suppose this library could, in theory, use |
Haha, now I see from the examples in the README that it works with |
@cgibbard The minimal repro case is actually: data SampleGADT :: * -> * where
ReturnAErr :: a -> SampleGADT a |
However, very strangely, this works: data SampleGADT c a where
ReturnAErr :: c -> SampleGADT c a |
It seems it has trouble adding constraints to the very last argument of the type? |
Indeed the last argument is explicitly dropped via aeson-gadt-th/src/Data/Aeson/GADT/TH.hs Line 70 in cd738fa
|
Just FYI I also tried this library out and got: {-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
module T where
import Data.Aeson.GADT.TH
data Expr a where
IfE :: Expr Bool -> Expr a -> Expr a -> Expr a
ListE :: [Expr a] -> Expr [a]
PureE :: a -> Expr a
deriveJSONGADT ''Expr
|
For any case where you think it should generate an instance, it would be really good if you could write one by hand for me to be able to understand what code it is that you'd like the TH to generate. I know there are a few deficiencies, but remember that it's writing an instance of FromJSON (Some (MyType a_1 a_2 ... a_(n-1))) for you -- leaving the last variable out. So if that variable needs to be constrained in some way, there's nowhere to put the constraint. Also, if pattern matching on other arguments to your data constructor won't determine the type of something we need to FromJSON, you're generally going to be hosed. In the case of ReturnAErr / PureE above, at what type should parseJSON be applied to parse the argument, in the Some SampleGADT / Some Expr instances? Of course, there is a real bug here: the error message really sucks, and I apologise for that. It would be good to figure out various things we can do to maybe produce a more informative one. |
I ended up with a manual instance using Typeable https://gist.github.com/chrisdone/5f584fed711299a1312f87b236d7df59 I'm not sure whether there is an automated way to work with this kind of GADT or not. |
I don't currently have code which checks for Typeable instances in resolving stuff like this, but it would be a possible thing to do. The trick with "OK" in that code there is probably harder to support though. Another way to factor things would be to use something like:
However, generating the instance for OK presently fails with a similar error message, and that one I don't think should be an issue, and which I'm fairly certain was working at some point in the past. The generated instance should look something like this:
Hopefully the changes I've started working on to make the various bits of GADT-related TH we use more robust will eventually fix that en passant (as soon as I can pop them off my stack and finish them). Trying it by hand, I'm not 100% sure how to make the parser for ListE go through mechanically though... hmm. |
CallStack (from HasCallStack):
error, called at src\Data\Aeson\GADT\TH.hs:131:21 in aeson-gadt-th-0.1.2.0-AuMd3MxiXrSK9OJwKOUSr:Data.Aeson.GADT.TH
Code: deriveJSONGADT ''FlowArrEx
|
1 | {-# LANGUAGE DataKinds #-}
| ^
The text was updated successfully, but these errors were encountered: