[Haskell-cafe] first post

Donn Cave donn at drizzle.com
Wed Nov 30 19:34:32 EST 2005

On Thu, 1 Dec 2005, raptor wrote:

> Whats wrong with following code :
> module Main where
> main = putStrLn "hi"
> parse str = take 10 str
> load = do
>         content <- readFile "parse.hs"
>         return content

Nothing!  It works, output is "hi".  "load" isn't used, but its
type would be "load :: IO String", so if you want to use it:

  main = do
          content <- load
          putStrLn (show content)

> i tried different combinations, but still cant figure out...
> How do u use an "IO String" in normal "String" functions..
> I want to particulary slurp file in a string and then make
> funny things with it...spliting to lines,parsing them and
> building hash like strucutre of it...etc.

Well, "main" is an example, and actually "load" is another
example - you don't really do much with your value in "load",
but you would find that the value has type String there.
The catch is that of course you must use this notation (<-),
and whatever "load" returns will be IO something.  But you
can use that in main, etc.

This may not make much sense without a little more exposure
to the underlying principles, but if you're just trying different
combinations, it should give you some ideas.

By the way, in your style of writing, does "..." end a
sentence, or should that be interpreted in some other way?

	Donn Cave, donn at drizzle.com

More information about the Haskell-Cafe mailing list