小编Geo*_*ppa的帖子

在Haskell中使用UTF-8作为IO String读取文件

除非文件具有utf-8characteres,否则我有以下代码可以正常工作:

module Main where
import Ref
main = do
    text <- getLine
    theInput <- readFile text
    writeFile ("a"++text) (unlist . proc . lines $ theInput)
Run Code Online (Sandbox Code Playgroud)

有了utf-8 characteres,我得到了这个: hGetContents: invalid argument (invalid byte sequence)

由于我正在使用的文件有UTF-8字符,我想处理此异常,以便重用从中导入的函数(Ref如果可能).

有没有办法读取UTF-8文件,IO String因此我可以重用我Ref的函数?我应该对我的代码做什么修改?提前致谢.

我附加了我的Ref模块中的函数声明:

unlist :: [String] -> String
proc :: [String] -> [String]
Run Code Online (Sandbox Code Playgroud)

来自前奏:

lines :: String -> [String]
Run Code Online (Sandbox Code Playgroud)

haskell utf-8

9
推荐指数
2
解决办法
1748
查看次数

连接到在无业游民计算机上运行的Node JS服务器

node http servervagrantVM 上运行很简单。我想用我本地计算机上的浏览器解决这个问题。

varhttp=require("http");

http.createServer(function(request,response){
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(3000);
Run Code Online (Sandbox Code Playgroud)

这是我的Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = "ubuntu/xenial64"
    config.vm.network "forwarded_port", guest: 80, host: 8080
    config.vm.provision "shell", path: "config.sh"
end
Run Code Online (Sandbox Code Playgroud)

我不知道如何从浏览器中解决它。

每当我curl localhost:3000在无所事事的VM中执行操作时,都会收到Hello world消息。

正如流浪转发中所建议的,This site can’t be reached每当我尝试打开时localhost:8080,我都会从我的本地机器上得到。

virtualbox localhost portforwarding node.js vagrant

0
推荐指数
1
解决办法
2147
查看次数