Hello. First of all I am a beginner in Haskell, and I must confess I do not yet fully understand it. I need to write a program in Haskell, though, and I am having some difficulties... What I would like to ask, is how can I take a string from a list, and manipulate it, in order to convert it to an integer. Any help would be very appreciated. Thank you very much, Dimitris
You should have a look at the Read class. A member a of the Read class has a function read :: String -> a. so, for example, you can say: (read "5.0") :: Double to read this as a double. You could also read it as an integer or something. If you have a list of strings that you want to convert to a list of integers, you could do: map (\x -> (read x)::Double) [list of strings] Hope that helps. - Hal -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Thu, 7 Feb 2002, DK wrote:
Hello. First of all I am a beginner in Haskell, and I must confess I do not yet fully understand it. I need to write a program in Haskell, though, and I am having some difficulties...
What I would like to ask, is how can I take a string from a list, and manipulate it, in order to convert it to an integer. Any help would be very appreciated.
Thank you very much, Dimitris
"DK" <psycho_jim_4@yahoo.com> writes:
What I would like to ask, is how can I take a string from a list, and manipulate it, in order to convert it to an integer.
That's very simple, and I'm of course happy to help out with homework questions. (That's what mailinglists are for, after all.) So, how about:
convert :: String -> Integer convert _ = 0
(This converts all strings to the integer zero.) HTH, HAND. :-) -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (3)
-
DK -
Hal Daume III -
ketil@ii.uib.no