ghci 'Not in scope:' message

HaskellGhci

Haskell Problem Overview


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?

Haskell Solutions


Solution 1 - Haskell

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

Solution 2 - Haskell

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser181351View Question on Stackoverflow
Solution 1 - HaskellYasirAView Answer on Stackoverflow
Solution 2 - HaskellMaqboolView Answer on Stackoverflow