Haskell: writing the result of a computation 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 6:13 UTC
Read the original article Hit count: 236

Filed under:

I have a function which creates a tuple after computation, but I would like to write it to file.

I know how to write to a file using writeFile, but do not know how to combine the 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 a list, but I want this function to receive input from a file, and 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