
George Young wrote:
[linux, ghci 6.4.3.20060820, hugs May 2006]
I have just started learning Haskell. I have hugs and ghci under linux, and I'm going through the Gentle Introduction to Haskellhttp://www.haskell.org/tutorial, so far through section 4, "case expressions and pattern matching". I'm a python programmer, with background in maclisp, scheme, T, C, C++, and a little J.
I'm confused about what sort of things I can type at the interpreter prompt, and what things have to be loaded as a module. I keep trying to treat the prompt like a lisp or python REPL, which is obviously wrong. Can someone set me straight?
GHCi allows expressions, plus anything valid as a statement in a do block (of IO). That's why you can use let without an "in" clause to make bindings that stick around - you're getting the let form allowed in do blocks. You can also bind use the arrow bindings, to get result out of IO actions, like some_even <- fmap (*2) randomIO. (isn't this a good answer to the perennial newbie question "how do I get a out of IO a"?) I usually work with GHCi (ghci MyModdule.hs) next to an editor, examining things in GHCi, then changing the code or adding things like data type declarations that can't be done interactively, and reloading the file (with :r). It works pretty well, though copying important declarations from the session into the module to preserve them across a reload is a bit annoying. The usual approach of making a REPL accept any valid code in the language wouldn't work so well for Haskell. It would be tough to implement, because declarations can come in any order, and extremely aggravating to use, because declarations can't be shadowed. Allowing class and type declarations interactively would be nice (perhaps Hugs already does?), but not a massive improvement alone. Maybe if there were a feature to extract all the code necessary to reproduce some interactively defined value? Brandon