除非文件具有utf-8
characteres,否则我有以下代码可以正常工作:
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) 我node http server
在vagrant
VM 上运行很简单。我想用我本地计算机上的浏览器解决这个问题。
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
,我都会从我的本地机器上得到。