开发者

ghci 'Not in scope:' message

开发者 https://www.devze.com 2023-02-19 05:17 出处:网络
I\'m going through the \'Learn you a Haskell\' tutorial and I am at this part: lucky :: (Integral a) => a -> String

I'm going through the 'Learn you a Haskell' tutorial and I am at this part:

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

When I try to execut开发者_C百科e this line I get:

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

What am I doing wrong?


This is not a function code, it's function signature which can only be saved in a module along with function definition and the be loaded to GHCi.

This signature means that you're going to define a function lucky which gets an Integer and returns a String.

However if you're composing your functions using GHCi as interactive interpreter, you can let Haskell infer your function's type, e. g.:

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


If you want to try in the GHCI you could use multi-line command block

:{
lucky :: Int -> String
lucky a = show(a)
:}

:type lucky 
lucky :: Int -> String
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号