[Haskell-beginners] the role of assignments

prad prad at towardsfreedom.com
Thu Jul 1 19:59:35 EDT 2010


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


More information about the Beginners mailing list