我制作了一个小型的生命游戏程序,它自己迭代几代。问题是每次迭代时, putStrLn 函数都会显着减慢,我无法弄清楚原因。这是代码:
import Control.Concurrent
data CellState = Dead | Alive
data Position = Position Integer Integer
type Generation = Position -> CellState
is_alive :: CellState -> Bool
is_alive Alive = True
is_alive Dead = False
neighbors :: Position -> [Position]
neighbors (Position x y) =
[(Position (x-1) (y-1)), (Position x (y-1)), (Position (x+1) (y-1)), (Position (x+1) y),
(Position (x+1) (y+1)), (Position x (y+1)), (Position (x-1) (y+1)), (Position (x-1) y)]
alive_neighbors :: Generation -> Position -> Int
alive_neighbors generation position …Run Code Online (Sandbox Code Playgroud) 使用 Sharp 对 JPG 进行缩放和着色后,我立即删除输入文件。当我上传同名的新文件时,Sharp 将输出旧文件。我在 Ubuntu 16.04 上运行 NodeJS。
这是编辑文件的代码:
sampleFile.mv(__dirname + "/" + name + "." + ext, function(err) {
if (err)
return res.status(500).send(err);
res.send('File uploaded!');
if (ext != "xlsx") {
// This will attempt to resize the images
console.log("Sharpening image")
sharp(__dirname + "/" + name + "." + ext).resize({ height: 27 }).flatten( { background: '#ffffff' } ).toFile("/var/www/my_ip/file.jpg")
.then(function(newFileInfo) {
// newFileInfo holds the output file properties
console.log("Success")
try {
fileSystem.unlinkSync(__dirname + "/" + name + "." + …Run Code Online (Sandbox Code Playgroud)