-
Notifications
You must be signed in to change notification settings - Fork 42
interpret
relies on the Show
instance of TypeRep
, which isn't right once kinds matter.
#88
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
Comments
I set up a fork for trying to fix this. Here's the commit with what I've got so far: In effect, this strips out all kind specifications. It's not clear to me if that's ok. The other two alternatives would be:
Supposing either of those were necessary though, we may be out of luck. Kind Signatures are a language extension, and I assume we can't just activate an extension in the wrapped GHC... right? |
Thanks! I don't see the part which filters out the kind specifications; we definitely don't want to filter out all the type arguments which look like kinds, only the arguments which should be invisible. I assume that |
hint allows the user to choose which language extensions they want to enable and disable. I would be fine with forcing KindSignatures to always be on, but I don't understand how that would help. The type already has kind |
I'm not sure what you mean by invisible arguments, or by type arguments which look like kinds, so I don't know if that could be a problem or not. splitTyConApp gives us access to a TyCon instead of a TypeRep; this happens to leave out the kind signature. I'm pretty sure this could only ever matter if the type constructor in question were polykinded. I don't know if it matters when the constructor is polykinded.
I haven't been able to think of any exceptions to this, but I don't want to trust my own knowledge. Supposing all the above hand-wringing is over nothing, I would next add an appropriate unit/regression test and then open a pull request? |
Consider these three types: {-# LANGUAGE DataKinds, KindSignatures, PolyKinds #-}
data Foo a deriving Typeable
data Bar (a :: k) deriving Typeable
data Baz k (a :: k) deriving Typeable Thanks to the GHC Haskell now supports dependent kinds, which is what makes Let's look at the λ> typeRep $ Proxy @(Foo 'True)
Foo Bool 'True
λ> typeRep $ Proxy @(Bar 'True)
Bar Bool 'True
λ> typeRep $ Proxy @(Baz Bool 'True)
Baz Bool 'True The Show instance prints the invisible When you wrote "this strips out all kind specifications", I was worried that you were only looking at cases like Up to now I thought your λ> splitTyConApp $ typeRep $ Proxy @(Foo 'True)
(Foo,['True])
λ> splitTyConApp $ typeRep $ Proxy @(Bar 'True)
(Bar,['True])
λ> splitTyConApp $ typeRep $ Proxy @(Baz Bool 'True)
(Baz,['True]) So we need to keep searching for a proper solution! I haven't yet looked for a way to distinguish between visible and invisible type arguments, I don't know if it's even possible using Typeable's API. Thanks for your effort so far, and if you have more questions, don't hesitate to ask! |
To be honest, I don't know either! |
Since you already wrote some code, I do think it would make more sense to discuss that code in a PR rather than an issue, as it would allow CI to run on your code and it would allow me to write review comments next to your code. We now know that your code is not quite correct yet, but it doesn't need to be perfect before sending it as a PR! Creating a PR is a perfectly good way to start a discussion. As is opening an issue; I'm not saying you should have opened a PR, I'm saying you can if you want :) Thanks again for contributing, this project deserves a lot more love than I currently give it! |
using ghci's |
I reported it the the ghc team at https://gitlab.haskell.org//ghc/ghc/issues/14341#note_246287 |
Thank you! |
I did some experiments with everything I could grab from Where else might the visibility information be stored?
TemplateHaskell's
And so does
|
Good news: while I can convert
Since I do need to provide the |
I have the same issue with the extensible package. Here is a minimalist example that fails with {-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
module Main (main) where
import Data.Functor.Identity
import Data.Extensible
import Language.Haskell.Interpreter
foo :: '[Int] :/ Identity
foo = embed (Identity (1 :: Int))
fooStr :: String
fooStr = "embed (Identity (1 :: Int))"
interpretSum :: String -> IO ()
interpretSum expr = do
a <- runInterpreter $ do
setImports ["Prelude", "Data.Functor.Identity", "Data.Extensible"]
set [languageExtensions := [DataKinds, TypeOperators]]
interpret expr (as :: '[Int] :/ Identity)
print a
main :: IO ()
main = interpretSum fooStr
|
interpret
relies on theShow
instance ofTypeRep
, which doesn't yield syntactically valid expressions when it needs to specify the contextual kind of a polykinded constructor.You can see a concrete example of the problem this causes on Stack Overflow.
It looks like this might be fixable by using
Type.Reflection....
instead ofData.Typeable....
. I'd be glad to try to help; we're right at the limits of my current understanding of Haskell.Issue thread at Polysemy, for reference.
The text was updated successfully, but these errors were encountered: