gpt4 book ai didi

haskell - 查找局部函数的推断类型

转载 作者:行者123 更新时间:2023-12-03 22:30:10 24 4
gpt4 key购买 nike

ghci(或 ghc)有没有办法找到推断的局部函数类型是什么?

例如。如果我有一个功能

f l = map f' l
where f' = (+1)

有没有 :t - 类似 ghci 的方式来查看 f' 的推断类型是?

最佳答案

确实有,感谢 hammar 的精彩回答 here .这是简短的版本:

Prelude> :l /tmp/foo.hs
[1 of 1] Compiling Main ( /tmp/foo.hs, interpreted )
Ok, modules loaded: Main.
*Main> :break f
Breakpoint 0 activated at /tmp/foo.hs:(1,1)-(2,18)
*Main> f [1..10]
Stopped at /tmp/foo.hs:(1,1)-(2,18)
_result :: [b] = _
[/tmp/foo.hs:(1,1)-(2,18)] *Main> :step
Stopped at /tmp/foo.hs:1:7-14
_result :: [b] = _
f' :: b -> b = _
l :: [b] = _
[/tmp/foo.hs:1:7-14] *Main> :t f'
f' :: b -> b

关于haskell - 查找局部函数的推断类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15034392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com