58

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 execute this line I get:

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

What am I doing wrong?

1

2 Answers 2

63

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
1
  • 1
    Is there any way to add another definition to ghci with pattern matching. Something like let lucky 4 = "four" Sep 16, 2016 at 11:27
17

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.