<div id="counter">
<input type="button" id="buttonCountPlus" value="+">
<div id="buttonCountNumber">1</div>
<input type="button" id="buttonCountMinus" value="-">
</div>
<div id="calculation">150</div> // 150 просто число для наглядности вычисления
let calculate = document.getElementById("calculation");
let count = document.getElementById("buttonCountNumber");
calculation = document.getElementById("calculation").innerHTML;
document.getElementById("buttonCountPlus").onclick = function() {
let countPlus = count.innerHTML;
if(+countPlus <= 3){
count.innerHTML++;
let countPlus = count.innerHTML;
calculate.innerHTML = calculations(countPlus) ;
}
}
document.getElementById("buttonCountMinus").onclick = function() {
let countMinus = count.innerHTML;
if(+countMinus >= 2){
count.innerHTML--;
let countMinus = count.innerHTML;
calculate.innerHTML = calculations(countMinus) ;
}
}
calculations = (count) => {
return calculation+` * ${count} = ` + (+count)*(+calculation);
}
λ> myfun = (^2)
λ> myfun <$> [1, 2, 3]
[1,4,9]
λ> myfun = (^2)
λ> map myfun [1, 2, 3]
[1,4,9]
Есть функция:
pow2 x = x ^ 2
Есть такой список:
[1, 2, 3, 4, 5]
Как вызвать функцию для всех элементов списка
squares :: Num a => [a] -> [a]
squares lst = do
x <- lst
return (x ^ 2)
squares' :: Num a => [a] -> [a]
squares' lst = lst >>= \x -> return (x ^ 2)
squares'' :: Num a => [a] -> [a]
squares'' lst = [x ^ 2 | x <- lst]
fx f lst = [f x | x <- lst]
main = do
print $ fx (^2) [1, 2, 3]
print $ squares [1, 2, 3]
print $ squares' [1, 2, 3]
print $ squares'' [1, 2, 3]
module Main where
import System.IO
main :: IO ()
main = do
content <- readFile "file.dat"
putStrLn content
putStr "enter x = "
-- Флюшим вывод не забываем про ленивость языка
hFlush stdout
x <- getLine
print (read x :: Int)
writeFile "file.dat" x
Надо вот это --> For a comprehensive tutorial on using IO monad, look at the Haskell I/O inside: Down the Rabbit's Hole