1

If I enter any function type definition in WinGHCi, such as the following from learnyouahaskell.com

factorial :: Integer -> Integer  

I always get

<interactive>:8:1: error:
    Variable not in scope: factorial :: Integer -> Integer

Surely I am doing something wrong with the environment, but I don't know how to fix it.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
KenW
  • 11
  • 1
  • Use: `let { factorial :: Integer -> Integer ; factorial n = if (n==0) then 1 else n*factorial (n-1) }`. Or maybe look [there](https://stackoverflow.com/a/3532505/11282404). – jpmarinier Mar 30 '20 at 14:31
  • 1
    @JosephSible-ReinstateMonica and jpmarinier: I suggest using [*Function definition by special cases in GHCi*](https://stackoverflow.com/q/42593284/2751851) as a target instead, as the other Q&A has more extraneous details, and the highest scoring answer that covers `:{` and `:}` inaccurately suggests that they affect indentation. – duplode Mar 30 '20 at 15:42
  • Your definition (which I presume is the `factorial` from [this LYAH chapter](http://www.learnyouahaskell.com/types-and-typeclasses)) has two lines, so you need to use multiline input in GHCi, as the linked questions explain. Without doing that, GHCi sees the `factorial :: Integer -> Integer` as an attempt to use `factorial`, rather than as a type signature, which is why you get a "not in scope" error. – duplode Mar 30 '20 at 15:46
  • @duplode I agree that's a better target, but once someone votes for a duplicate, they can never change it, since you can only vote to close the same question once ever, even if you retract your old vote – Joseph Sible-Reinstate Monica Mar 30 '20 at 15:55
  • 1
    @JosephSible-ReinstateMonica Indeed -- when I wrote the comment I hadn't noticed your vote. In any case, now that the question is closed I can edit the duplicate list, so all is fine :) – duplode Mar 30 '20 at 15:58

0 Answers0