为什么我只获得“不在范围内”的变量?

问题描述 投票:2回答:1

我正在从一个受欢迎的book学习Haskell。

它包括following ghci command

ghci> Just ord <*> Nothing  
Nothing

当我在ghci中运行时,我得到:

<interactive>:1:6: error:
    • Variable not in scope: ord :: a0 -> b
    • Perhaps you meant one of these:
        ‘or’ (imported from Prelude), ‘odd’ (imported from Prelude)

我认为有一个拼写错误,或者是由于作者错误或者Haskell的版本改变了语法。

我的问题是:为什么我为variable not in scope获得Just ord <*> Nothing

haskell
1个回答
6
投票

A quick search for "ord" on Hoogle透露it lives in the Data.Char module。 (我不知道它是否总是存在,或者它是否最近才被移动到那里。)所以你只需要将Data.Char导入你的ghci会话。

ghci> import Data.Char
ghci> Just ord <*> Nothing
Nothing
© www.soinside.com 2019 - 2024. All rights reserved.