haskell - -ddump-simpl 是获得具体类型的最佳方法吗?
我之前写过一个似乎可以工作的函数,但不幸的是我没有很好地编写代码,现在必须再次弄清楚[我正在修改我正在使用的 monad 变压器堆栈]。
run_astvn ::
LowerMonadT (StateT LowerSketchData Identity) β
-> Seq SketchAST
run_astvn x = get_ast2 $ runIdentity $
runStateT (runStateT (runStateT x empty) empty)
(LowerSketchData Set.empty)
where get_ast2 = snd . fst
我想获取 get_ast2
的具体类型。我似乎能够通过终端输出添加标志 -ddump-simpl
和 grep 直到我发现,(清理了一下)
(((β, Seq SketchAST), Seq SketchAST), LowerSketchData) -> Seq SketchAST
(抱歉,这对其他人来说可能是无意义的,但重点是它对我很有用。)有没有更快/更方便的方法来做到这一点?如果不是很明显,我在这种情况下所说的“具体”的意思是上面的类型是有用的;知道 snd 的类型。 fst 不是:)。
I had previously written a function that seems to work, but unfortunately I didn't write the code very nicely, and now have to figure it out again [that I'm modifying the monad transformer stack I'm working with].
run_astvn ::
LowerMonadT (StateT LowerSketchData Identity) β
-> Seq SketchAST
run_astvn x = get_ast2 $ runIdentity $
runStateT (runStateT (runStateT x empty) empty)
(LowerSketchData Set.empty)
where get_ast2 = snd . fst
I want to get the concrete type of get_ast2
. I seem to be able to add the flag -ddump-simpl
and grep through my terminal output until I find, (cleaned up a little)
(((β, Seq SketchAST), Seq SketchAST), LowerSketchData) -> Seq SketchAST
(Sorry this is likely nonsense to everyone else, but the point is it is useful for me.) Is there a faster / more convenient way to do this? In case it's not obvious, what I mean by "concrete" in this case is that the above type is useful; knowing the type of snd . fst
is not :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前我知道有两种方法可以做到这一点,它们都是黑客。第一种是使用隐式参数:
然后,在 ghci 中:
另一种方法是故意给出错误的类型签名并检查编译器如何抱怨。
这会给出错误:
将错误的类型更改为
() -> ()
:现在我们知道类型应该类似于(),因为编译器抱怨:
(((β, Seq SketchAST), Seq SketchAST), LowerSketchData) -> ()
。最后一次迭代去掉了最终的...所以另一个
()
应该是Seq SketchAST
。There's two ways I know of to do this currently, and they're both sort of hacks. The first is to use implicit parameters:
Then, in ghci:
The other way is to give an intentionally wrong type signature and check how the compiler complains.
This gives the error:
Changing the wrong type to
() -> ()
:So now we know the type should look like
(((β, Seq SketchAST), Seq SketchAST), LowerSketchData) -> ()
. One last iteration gets rid of the final()
, because the compiler complains that:...so the other
()
should beSeq SketchAST
.对编译器撒谎。添加错误的类型签名,然后它应该回复“无法将错误的类型与真实类型匹配”或当前的确切消息。
Lie to the compiler. Add a wrong type signature, then it should reply with 'Couldn't match wrong type with real type' or whatever the exact message currently is.