[Haskell-cafe] IO() and other datatypes

David McBride toad3k at gmail.com
Sun Mar 4 20:06:55 CET 2012


Just use this rule of thumb.  If it is a monad (like IO Int, IO
String) use do <- notation.  If it isn't a monad (like Int, String),
just use let syntax, same as you did with the first list.

main = do
  let ttime = [8,20,10,15]
      a = dauer ttime  (OPTIONAL let a = dauer ttime)
  putStrLn a

On Sun, Mar 4, 2012 at 1:41 PM, Kevin Clees <k.clees at web.de> wrote:
> Dear Haskell programmers,
>
> I'm very confused, because I really don't know how to handle with IO's and
> other datatypes, such as Int or String.
> If I want to build a haskell program can I only use IO() method outputs ?
> How can I "give" a Int result from a different method back to the main?
> Would this mean that I have to create only IO() outputs? Is this correct?
>
> For example:
>
> -- A User has to choose something, so I need a IO() datatype
> main :: IO()
> main = do
> [...]
> let listtournementTime = [8,20,10,15]
>
> -- This is wrong: Couldn't match expected type `IO t0' with actual type
> `Int'
> -- The results of the method dauer is a Int. Do I have to transform the
> method to an IO() Output
>
> a <- Dauer listtournementTime
>
>
> [...]
>
>
> -- the methods
>
> dauer:: [Int] -> Int
> dauer (x:xs)
>     | laenge(x:xs) == 1 = 0
>     | mod (laenge (x:xs)) 2 == 0 = (tmp x xs) + dauer xs
>     | mod (laenge (x:xs)) 2 /= 0 = dauer xs
>     | otherwise = 999999 -- failure
>
> tmp:: Int -> [Int] -> Int
> tmp y (x:xs) = x-y
>
> laenge        :: [a] -> Integer
> laenge []     =  0
> laenge (x:xs) =  1 + laenge xs
>
> The last three methods are working correct, if I directly put some data into
> the methods, like:
> dauer [10,15]
> ===Result===> 5
>
>
> Thank you for any help
>
> Best greetings from Namibia
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list