Re: [Haskell-cafe] IO() and other datatypes

2012-03-12 Thread Kevin Clees
Great, Thank you !

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] IO() and other datatypes

2012-03-04 Thread Kevin Clees
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 = 99 -- 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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO() and other datatypes

2012-03-04 Thread David McBride
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.cl...@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 = 99 -- 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@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe