Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.haskell > #359
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.haskell |
| Subject | Re: modifying a list |
| Date | 2016-02-26 16:58 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87twkvo1cv.fsf@bsb.me.uk> (permalink) |
| References | <6b2b6571-7768-4c59-9e12-94afc82ac110@googlegroups.com> |
pip7kids@gmail.com writes: > I want to be able to modify my imported data on variable "y". You are not really modifying it (quite rightly -- that's not how Haskell works) but the problem is a simple arithmetic one. Unlike most other languages, Haskell does not have automatic type promotions when doing arithmetic so you need to say how the multiplication of an Int by 2.6 should be done. Presumably you want floating point multiplication so either change rList :: String -> IO [Int] to rList :: String -> IO [Float] or use the utility function fromIntegral in the list comprehension: print ([fromIntegral x * 2.6 | x <- y]) <snip> > This does not work ............ > import System.IO > > -- data.txt = [1,2,3,4,5,6,7,4,3,2,3,4,5,6] > > main = do x <- readFile "data.txt" > y <- rList x > print (sum y) > print ([x * 2.6 | x <- y]) -- this is what I am trying to achieve > > rList :: String -> IO [Int] > rList = readIO -- Ben.
Back to comp.lang.haskell | Previous | Next — Previous in thread | Find similar | Unroll thread
modifying a list pip7kids@gmail.com - 2016-02-26 08:25 -0800 Re: modifying a list Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-26 16:58 +0000
csiph-web