GHCi won't allow type declaration as shown in LYAHFGG

I have been working my way through "Learn You a Haskell for Greater Good" and am stumped when I get to the "Syntax in Functions - Pattern Matching" section. The book shows the following expression... ghci> lucky :: (Integral a) => a -> String ...but when I try to execute it in GHCi I get the following error... <interactive>:1:1: Not in scope: `lucky' What am I missing? Stan Kulp 4421 W North Pinebrook Lane Columbia, MO 65203 Home: 573-234-2065 Work: 573-522-5075 Cell: 573-864-6051

I don't think GHCi allows function and type definitions in interactive mode.
You have to write the functions in a source file and then load it. You can
then call the functions as usual.
Homero Cardoso de Almeida
On Thu, May 31, 2012 at 4:48 PM, Stan Kulp
I have been working my way through "Learn You a Haskell for Greater Good" and am stumped when I get to the "Syntax in Functions - Pattern Matching" section.
The book shows the following expression...
ghci> lucky :: (Integral a) => a -> **String
...but when I try to execute it in GHCi I get the following error...
<interactive>:1:1: Not in scope: `lucky'
What am I missing?
Stan Kulp 4421 W North Pinebrook Lane Columbia, MO 65203
Home: 573-234-2065 Work: 573-522-5075 Cell: 573-864-6051
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Thu, May 31, 2012 at 3:48 PM, Stan Kulp
I have been working my way through "Learn You a Haskell for Greater Good" and am stumped when I get to the "Syntax in Functions - Pattern Matching" section.
The book shows the following expression...
ghci> lucky :: (Integral a) => a -> **String
...but when I try to execute it in GHCi I get the following error...
<interactive>:1:1: Not in scope: `lucky'
What am I missing?
ghci is intended for interactive evaluation; it doesn't (currently; this might change in future versions) do declarations the same way you would in a source file. You can still do them with do-style let binding: Prelude> let lucky :: (Integral a_ => a -> String; lucky = ... (This all has to fit on a single line unless you use braces and have done ":set +m"; this may also require a recent GHC.) -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Stan Kulp
I have been working my way through "Learn You a Haskell for Greater Good" and am stumped when I get to the "Syntax in Functions - Pattern Matching" section.
The book shows the following expression...
ghci> lucky :: (Integral a) => a -> String
As far as I can see, the live version of `the section you mention`_ on learnyouahaskell.com does not contain this text - it doesn't have the "ghci> " at the beginning of the line. Besides what others have said in response to your question, I would add that you should make sure to read LYAH on the website if possible - other sources might be out of date, as I think the author does update the website version from time to time. .. _the section you mention: http://learnyouahaskell.com/syntax-in-functions#pattern-matching -Keshav

I just tried here, and got no problems.
lucky.hs:
lucky :: (Integral a) => a -> String
lucky 7 = "LUCKY NUMBER SEVEN!!!"
lucky x = "Sorry, you're out of luck, pal..."
ghci:
:load "/path/to/lucky.hs"
[1 of 1] Compiling Main ( /path/to/lucky.hs, interpreted )
Ok, modules loaded: Main.
*Main> lucky 7
"LUCKY NUMBER SEVEN!!!"
*Main> lucky 200
"Sorry, you're out of luck, pal..."
*Main>
I would suggest verifying my ghc installation or for any "funky" chars in
the file.
Homero Cardoso de Almeida
On Thu, May 31, 2012 at 6:16 PM, Keshav Kini
I have been working my way through "Learn You a Haskell for Greater Good" and am stumped when I get to the "Syntax in Functions - Pattern Matching"
Stan Kulp
writes: section. The book shows the following expression...
ghci> lucky :: (Integral a) => a -> String
As far as I can see, the live version of `the section you mention`_ on learnyouahaskell.com does not contain this text - it doesn't have the "ghci> " at the beginning of the line. Besides what others have said in response to your question, I would add that you should make sure to read LYAH on the website if possible - other sources might be out of date, as I think the author does update the website version from time to time.
.. _the section you mention: http://learnyouahaskell.com/syntax-in-functions#pattern-matching
-Keshav
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Brandon Allbery
-
Homero Cardoso de Almeida
-
Keshav Kini
-
Stan Kulp