Re: String manipulation.

2002-02-08 Thread Ketil Z. Malde

DK [EMAIL PROTECTED] 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
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: String manipulation.

2002-02-07 Thread Hal Daume III

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| [EMAIL PROTECTED]
  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
 

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



RE: String manipulation.

2002-02-07 Thread Chris Angus
Title: RE: String manipulation.





You may want to use reads
as read will call error if the 
string is not an integer


or use something akin to the example below


readMaybeInt :: String - Maybe Int
readMaybeInt s = case reads s of
 [(x,_)] - Just x
 _ - Nothing




-Original Message-
From: Hal Daume III [mailto:[EMAIL PROTECTED]]
Sent: 07 February 2002 17:54
To: DK
Cc: [EMAIL PROTECTED]
Subject: Re: String manipulation.



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 | [EMAIL PROTECTED]
 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
 


___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell





Re: String manipulation.

2002-02-07 Thread DK
Title: RE: String manipulation.



Thank you very much I'll try both 
approaches.

Regards, Dimitris 
Keramidas