
<- isn't just for IO; it's part of "do" notation's syntactic sugar. It
is actually (in your first example) passing the unwrapped result
(String; not IO String) of ``readFile filename" to an anonymous
function.
I'd recommend reading ch. 14 of Real World Haskell (
http://book.realworldhaskell.org/read/monads.html )
On 7/1/10, prad
i'm trying to sort the assignment concept out in my mind. as i understand it so far,
<- is for IO so you can do something like someIOVar <- readFile filename this will be of type IO String
which is different from String as in
let someStrVar = "this is a string"
to work with an IO String you need to convert it into a String which seems to automatically happen inside a do structure as in:
main = do tmplX <- readFile "zztmpl.htm" navbx <- readFile "zznavb.htm" let page = U.replace tmplX "NAVX" navbx
are there some other ways to make IO String into String?
also, it seems that assignment is different for the '=' in a program vs ghci for functions:
sum x y = x + y (program) vs let sum x y = x + y (ghci)
but not for strings and other things because you must always preface assignment of values with 'let':
let a = 4
i suppose the let is there for variable assignments because such things necessitate a change of state and i've read that this is not desirable in functional programming - you have to work a little harder to do assignment than languages which just allow a = 4 b = 5 c = 6 etc
in haskell, is it preferable to do something like this:
var <- readFile fn someFunction var
or someFunction (readFile fn)
-- In friendship, prad
... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners