extreme newbie: hugs prompt vs load module

[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? Is there another tutorial that might be more appropriate for me? I am finding haskell quite appealing. I hope to start writing real (if small) applications to do some data analysis from our Postgres DB. Any hints? --George Young -- "Are the gods not just?" "Oh no, child. What would become of us if they were?" (C.S. Lewis)

Hello George, Wednesday, August 23, 2006, 6:16:12 PM, you wrote:
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?
in hugs you can only type expressions: such as "2*2" or "prod [1..10]". although there is a trick what sometimes help: let fac n = prod [1..n] in fac n it's also an expression, after all :) in ghci you can define functions with 'let' you can find more information about this in appropriate user guides, what is part of your installations and is also available online
Is there another tutorial that might be more appropriate for me?
"yet another haskell tutorial" commonly considered as more "gentle" than "gentle introduction" you can find "Getting started" and "Books and tutorials" links on the haskell.org. First page includes the most recommended books/tutorials while second contains more detailed explanations about their contents
I am finding haskell quite appealing. I hope to start writing real (if small) applications to do some data analysis from our Postgres DB. Any hints?
haskell.org -> "libraries and tools" -> "databases" -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Aug 23, 2006, at 10:16 AM, 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?
For the most part, the things you can enter at the GHCi or Hugs prompt are _expressions_. This mostly* excludes _declarations_, which are things like function definitions, datatype declarations, class and instance declarations, etc. Those things need to go into a source file. (*) 'let' expressions will allow you to define local functions as part of an expression, however. GHCi also has a slight variation of 'let' that allows you to define functions for the session.
Is there another tutorial that might be more appropriate for me?
The following tutorial is generally recognized as one of the better ones: http://www.cs.utah.edu/~hal/htut/
I am finding haskell quite appealing. I hope to start writing real (if small) applications to do some data analysis from our Postgres DB. Any hints?
There are several haskell database layers. I've had some luck with HDBC, which has a PostgreSQL driver. http://quux.org:70/devel/hdbc
--George Young -- "Are the gods not just?" "Oh no, child. What would become of us if they were?" (C.S. Lewis)
Rob Dockins Speak softly and drive a Sherman tank. Laugh hard; it's a long way to the bank. -- TMBG

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

You can always load things inside ghci with: :m i.e. Prelude> :m List Prelude List> :m Control.Concurrent Prelude Control.Concurrent> :m Control.Concurrent List Prelude List Control.Concurrent> 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?
Is there another tutorial that might be more appropriate for me?
I am finding haskell quite appealing. I hope to start writing real (if small) applications to do some data analysis from our Postgres DB. Any hints?
--George Young
participants (5)
-
Brandon Moore
-
Bulat Ziganshin
-
George Young
-
Robert Dockins
-
Shao Chih Kuo