-
Notifications
You must be signed in to change notification settings - Fork 63
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
Improve type inference on pfield
and hrecField
#275
Comments
Another example:- test :: Term s (PScriptContext :--> PAddress)
test = plam $ \x -> unTermCont $ do
txInps <- tcont $ pletFields @'["inputs"] $ pfield @"txInfo" # x
let
g = phead # hrecField @"inputs" txInps
let a = pfield @"resolved" # g
pure $ pfield @"address" # a This snippet gives out a bunch of errors. If you help out GHC a bit by providing an annotation on test :: Term s (PScriptContext :--> PAddress)
test = plam $ \x -> unTermCont $ do
txInps <- tcont $ pletFields @'["inputs"] $ pfield @"txInfo" # x
let
g :: Term _ (PAsData PTxInInfo)
g = phead # hrecField @"inputs" txInps
let a = pfield @"resolved" # g
pure $ pfield @"address" # a It still fails typecheck on
I have no idea how it managed to infer that The way to fix this is to provide an explicit type on the phead # (hrecField @"inputs" txInps :: Term _ (PBuiltinList (PAsData PTxInInfo))) Curiously, if I try to isolate it out a bit into this snippet- test' :: HRec '[Labeled "inputs" (Term s (PAsData (PBuiltinList (PAsData PTxInInfo))))] -> Term s (PAsData PTxInInfo)
test' x =
let
g :: Term _ (PAsData PTxInInfo)
g = phead # hrecField @"inputs" x -- but this works???
in g It no longer errors. What ???? |
pfield
when using the automatic removal of PAsData
pfield
and hrecField
I changed the title to be a bit more general since we have the PR merged now. |
Problem
E.g. In
examples/Examples/Api.hs
, if you removepfromData
without adding a type signature to the declaration, GHC chooses the wrong instance of the class, i.e.errors with
Solution until this is fixed
There are two good solutions:
pfromData
in those casesOther information
pfromData
#270The text was updated successfully, but these errors were encountered: