[Haskell-cafe] One question...
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sat Dec 9 12:17:31 EST 2006
wb:
> Hello to everyone!
>
> Two days ago I have found Haskell in Internet. It sounds very nice.
> I have read some articles, few examples, ... yes it sounds nice.
Great! Welcome to Haskell.
> Now my problem is connected with the "non-update" object feature.
> I can't write "variable" instead object because - from the meaning of the word
> ( variable ) - it has the possibility to CHANGE its value.
> Yes that my problem :-(
It's not a problem :)
> Let's assume that I've got to write the application that
> should works as follows:
>
> 1. At the beginning the user should write her/his name (for instance as the
> application parameter).
> 2. Let's assume that the application has many various functions defined
> inside, and - after printing each of the outputs - the name has to be
> printout.
>
> How should I think "properly" in Haskell to get described action?
Forget about updating values in place: its not necessary, and makes your
programs more flexible, and simpler to understand.
Here's a short program to read a user's name, and then apply various
functions to that name, printing the result.
import System.IO
import Data.Char
import System.Console.Readline
main = do
name <- do m <- readline "What is your name> "
return (maybe "Nobody" id m)
print (reverse name)
print (length name)
let n = map ord name
print n
print (sum n)
print name
We can run this:
$ runhaskell A.hs
What is your name> lambdaman
"namadbmal"
9
[108,97,109,98,100,97,109,97,110]
925
"lambdaman"
Just dive in (start on http://haskell.org).
-- Don
More information about the Haskell-Cafe
mailing list