I get an error in ghci when I try to define a new type:
Prelude> data Point = Pt Int Int <interactive>:1:0: parse error on input `data' Prelude> let data Point = Pt Int Int <interactive>:1:4: parse error on input `data'
What am I doing wrong?
Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!
From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.
Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)
Quits GHCi. You can also quit by typing control-D at the prompt. Attempts to reload the current target set (see :load ) if any of the modules in the set, or any dependent module, has changed.
titaniumdecoy
, I remember being helped with this sort of GHCi mystery when I learned the frequently made point that writing things like 'let square x = x * x' inside the GHCi is like writing let a = f b
with do
notation in the IO
monad -- say in this sort of example:
palindromize :: IO () palindromize = do a <- readFile "foo.txt" let b = reverse a putStrLn (a ++ b)
Similarly, when you redefine an expression in the GHCi, it's sort of like doing the following in do
notation, which is perfectly legitimate:
makeMess :: IO () makeMess = do a <- readFile "foo.txt" let b = reverse a putStrLn (a ++ b) let b = a putStrLn (a ++ b)
No one would declare a data type in the middle of such a sequence, but would do it elsewhere in the module. I might have guessed that there was some sort of theoretical objection, but Don S.'s remark suggests there isn't one.
It is possible since GHC 7.4.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With