You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PSCi中能否像GHCi的it那样引用上一命令执行结果?

PSCi 是否支持类似 GHCi 的 it 变量功能?

背景

我有 Haskell 开发背景,习惯在 GHCi 中使用it引用上一条命令的执行结果,示例如下:

ghci> 1+1
2
ghci> :type it
it :: Num a => a
ghci> it*2
4

问题与尝试

在使用 PureScript 的 REPL(PSCi)时,我想找到类似的功能,但查阅 PureScript 文档的《与 Haskell 的差异》页面及 PSCi 官方文档后,均未找到相关说明。

  • GHCi 中可通过:show bindings查看it的绑定情况,但 PSCi 的:show命令不接受bindings参数
  • 调用内置帮助命令:?,也未发现替代功能的提示
  • 尝试用:browse $PSCI查看模块内容,却触发了缩进错误

异常现象

部分错误提示显示 PSCi 似乎尝试将计算结果绑定到it,例如在spago repl会话中:

> import Prelude
> 1+'a'
Error found:
in module $PSCI
at :1:3 - 1:6 (line 1, column 3 - line 1, column 6)
  Could not match type
    Char
  with type
    Int
while checking that type Char
  is at least as general as type Int
while checking that expression 'a'
  has type Int
in value declaration it

但当计算成功执行后,it却无法被正常引用:

> 1+1
2
> it
Error found:
at <internal>:0:0 - 0:0 (line 0, column 0 - line 0, column 0)
  The value of it is undefined here, so this reference is not allowed.

这里触发的是CycleInDeclaration错误,与引用x或foo这类未定义名称时的UnknownName错误不同。我怀疑it在 PSCi 中有特殊机制,但作为 PureScript 新手,不知道后续该如何排查。

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 02:40:29