gpt4 book ai didi

haskell - ghci 'Not in scope:' 消息

转载 作者:行者123 更新时间:2023-12-03 06:03:02 26 4
gpt4 key购买 nike

我正在学习“向你学习 Haskell”教程,我正在这部分:

lucky :: (Integral a) => a -> String

当我尝试执行这一行时,我得到:

<interactive>:1:1: Not in scope: `lucky'

我做错了什么?

最佳答案

这不是函数代码,它是函数签名,只能与函数定义一起保存在模块中并加载到 GHCi。

此签名意味着您将定义一个函数lucky,它获取一个Integer并返回一个String

但是,如果您使用 GHCi 作为交互式解释器来编写函数,则可以让 Haskell 推断函数的类型,例如。例如:

ghci> let lucky x = show (x + 1)
ghci> :t lucky
lucky :: (Num a) => a -> String

关于haskell - ghci 'Not in scope:' 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5417623/

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