Haskell如何在Haskell中打印某些功能的信息。 :info func&quot&quot

发布于 2025-02-14 01:03:34 字数 330 浏览 0 评论 0原文

我是Haskell的新手。 有时,我写了一些复杂的功能,我自己不确定这些类型,因此我没有事先定义其类型,编译和运行仍然可以正常工作。 我想知道我是否可以像“ ghci>:info somenfunc”中的“ ghci&gtunc”中打印出该功能的类型,只是为了查看Haskell如何定义其定义。也许这样的事情:

f x = 2*x

main :: IO()
main = do
    print_info f

我知道我可以“ ghci>:load program.hs”&然后“:info f”,但对我来说,这是不合同的&有时与GHCI合作可能很丑。

I'm new to haskell.
Sometimes I write some complicated functions that I'm not so sure about the types myself, so I don't define its type beforehand, compiling and running still work fine.
I want to know if I can print out the types of that function like in "ghci> :info someFunc" in the program, just to see how Haskell define its. Maybe something like this:

f x = 2*x

main :: IO()
main = do
    print_info f

I know I can "ghci> :load program.hs" & then ":info f", but for me it is quite unconvenient & sometime working with ghci can be ugly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洛阳烟雨空心柳 2025-02-21 01:03:34

无法完成。您可以通过Togpable接近,但是即使在原则上也无法捕获多态性。

相反,我建议您设置Haskell语言服务器并将您的编辑器连接到它;大多数编辑至少支持您的连接级别,该连接级别使您可以悬停一个术语以查看其类型或在使用钥匙扣的定义中添加类型签名。

Can't be done. You can sort of get close with Typeable, but polymorphism cannot be captured, even in principle.

Instead, I recommend that you set up the Haskell Language Server and connect your editor to it; most editors support at least the level of connection that lets you hover a term to see its type or add a type signature to a definition with a keybinding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文