Haskell “ничего еще не делает” IO, или если без

Ваш скрипт должен быть выполнен после загрузки страницы, для этого вам нужно просто добавить свой js-код после html-кода: как показано ниже:

<html>
<head>
</head>
<body>
<p>
sdsdsd
</p>

<div>
<p>
hesdsd sdsdsd
</p>
</div>
<script >
function change(){
      var a = document.getElementsByTagName("p");
      for(var x = 0 ; x < a.length ; x++){
      a[x].innerHTML = "hello" ;}}
      change(); 
</script>

</body>
</html>
74
задан Don Stewart 17 April 2011 в 21:06
поделиться

2 ответа

Самый простой способ выполнить блокировку в монаде:

return ()

Однако для конкретной идиомы, которую вы используете, для вас уже создан комбинатор:

import Control.Monad
main = do s <- getLine
          when (s == "foo") $ putStr "You entered foo"

Это когда комбинатор ведет себя точно так же, как комбинатор doIf :)

106
ответ дан 24 November 2019 в 12:00
поделиться

You can use Hoogle to find functions, in this case: when.

In Hoogle, you can enter the type signature, and it will try to find matching functions in the standard libraries by unifying the types and reordering arguments.

In your case, you can simply enter the type of your doIf function: Bool -> IO () -> IO () . when is the third answer here, its reverse unless is there also.

19
ответ дан 24 November 2019 в 12:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: