Haskell Write Computation result to file

Posted by peterwkc on Stack Overflow See other posts from Stack Overflow or by peterwkc
Published on 2010-06-17T04:14:13Z Indexed on 2010/06/17 4:23 UTC
Read the original article Hit count: 237

Filed under:

Hello to all, i have function which create a tuple after computation but i would like to write it to file.

I know how to write file using writeFile but did not know how to combine computation and monads IO together in the type signature

This is my code.

invest :: ([Char]->Int->Int->([Char], Int) ) 
 -> [Char]->Int->Int->([Char], Int)
invest myinvest x y = myinvest x y

myinvest :: [Char]->Int->Int->([Char], Int)
myinvest w x y 
 | y > 0 = (w, x + y)
 | otherwise = error "Invest amount must greater than zero"
 where 

I have a function which computes the maximum value from list but i want to these function receive input from file then perform the computation of maximum value.

maximuminvest :: (Ord a) => [a] -> a
maximuminvest [] = error "Empty Invest Amount List"
maximuminvest [x] = x

maximuminvest (x:xs)   
     | x > maxTail = x  
     | otherwise = maxTail  
     where maxTail = maximuminvest xs

Please help. Thanks.

© Stack Overflow or respective owner

Related posts about haskell