Есть два примера, иллюстрирующих разницу
int a , b , c = 0 ;
a = ++c ;
b = c++ ;
printf (" %d %d %d " , a , b , c++);
a = 1
и значению c = 1
следующее значение присвоения следующего оператора от c = 1
до b, затем увеличить c на 1, так что значение b = 1
и значение c = 2
в printf
утверждение, что у нас есть c++
, это означает, что первоначальное значение c, равное 2, будет напечатано, а затем с приращением c увеличится на 1, поэтому printf
оператор выведет 1 1 2
, а значение c теперь равно 3
вы можете использовать http://pythontutor.com/c.html
int a , b , c = 0 ;
a = ++c ;
b = c++ ;
printf (" %d %d %d " , a , b , ++c);
printf
оператор ++c
будет увеличивать значение c на 1 сначала затем назначьте новое значение 3 для c, чтобы оператор printf
напечатал 1 1 3
The type of the main
function should be IO t
(where t
is a type variable). The type of map putStrLn ls
is [IO ()]
. This why you are getting this error message. You can verify this yourself by running the following in ghci
:
Prelude> :type map putStrLn ls
map putStrLn ls :: [IO ()]
One solution to the problem is using mapM
, which is the "monadic" version of map
. Or you can use mapM_
which is the same as mapM
but does not collect the returned values from the function. Since you don't care about the return value of putStrLn
, it's more appropriate to use mapM_
here. mapM_
has the following type:
mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
Here is how to use it:
ls = [ "banana", "mango", "orange" ]
main = mapM_ putStrLn ls
Ответ Аймана наиболее логичен в данной ситуации. В общем, если у вас есть [m ()]
и вы хотите m ()
,