我正在研究一个项目,我正在尝试创建一个服务器,监听端口8082上的本地主机地址(我已经预留了8081与另一台服务器)
public class Class2HTTPServer {
public static void main(String[] args) {
Class1 object1= new Class1 (300);// parameter I need for other stuff
Class2 object2= new Class2 (300,object1,5); // parameters for other unrelated stuff
int listen_on_port = 8082;
Class2HTTPMessageHandler handler = new Class2HTTPMessageHandler (
object2);
String server_port_string = System.getProperty(SystemConstants.PROPERTY_KEY_SERVER_PORT);
if(server_port_string != null) {
try {
listen_on_port = Integer.parseInt(server_port_string);
listen_on_portfs = Integer.parseInt(server_port_string);
} catch(NumberFormatException ex) {
System.err.println(ex);
}
}
ComponentHTTPServerUtility.createServer(listen_on_port, handler);
}
}
Run Code Online (Sandbox Code Playgroud)
这是ComponentHTTPServerUtility类:
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.eclipse.jetty.server.Server; …Run Code Online (Sandbox Code Playgroud) 我试图在Haskell中进行一些单元测试,这基本上就是我在代码中所做的:
module Test where
import Test.HUnit
test = TestList [TestLabel "running all the tests!"
$ TestList [
. . . . .
]]
run = runTestTT tests
Run Code Online (Sandbox Code Playgroud)
当我尝试使用gchi编译它时,我收到此消息:
Could not find module ‘Test.HUnit’
Use -v to see a list of the files searched for.
Failed, modules loaded: none
Run Code Online (Sandbox Code Playgroud)
我如何让HUnit工作?
我使用GHCi版本7.8.3
谢谢
我尝试通过cabal安装HUnit作为建议的答案,但后来我得到了错误:
Could not find module ‘Test.HUnit’ Perhaps you haven't installed the "dyn" libraries for
package ‘HUnit-1.2.5.2’?
Use -v to see a list of the files searched for.
Run Code Online (Sandbox Code Playgroud)
然后我使用了命令: …
我是Haskell的新手,我正在努力学习基础知识.我需要声明一个名为Pos的类型,它将具有两个整数然后我需要方向北,南,西,东,以便我可以根据方向改变位置.一旦我这样做,我需要创建一个称为移动的函数,它将获取移动列表和初始位置,并在所有移动后返回位置.这是我的代码,但我仍然坚持我必须遍历移动列表.
type Pos = (Int, Int)
data Direction = North | South | East | West
move :: Direction -> Pos -> Pos
move North (x,y) = (x, y+1)
move West (x,y) = (x-1, y)
move South (x,y) = (x, y-1)
move East (x,y) = (x+1, y)
moves :: [Direction] -> Pos -> Pos
moves [] (x,y) = (x,y)
moves (h:xs) (x,y)
| h == North = move North (x,y)
| h == West = move West (x,y)
| h …Run Code Online (Sandbox Code Playgroud) 我定义了两种数据类型:Point和Curve.Point的坐标有两个双精度,曲线有一个起点和一个表示曲线其余部分的点列表.我需要创建一个函数来创建这个曲线给定一个起点和一个点列表,但我不太明白我应该如何在曲线内的点列表中添加一个元素.这是我的代码:
data Point = Point Double Double deriving (Eq, Show)
point :: (Double, Double) -> Point
point (x, y) = Point x y
data Curve = Curve Point [Point] deriving (Eq, Show)
curve :: Point -> [Point] -> Curve
curve x [] = Curve x []
curve x [y] = Curve x [y]
curve x (y:ys) = curve x (y:ys)
Run Code Online (Sandbox Code Playgroud)
我很确定我的递归最终是错误的.那么你能给我一些关于如何在列表中添加一个点的指南吗?
谢谢
我一直在搞乱erlang,我试图找到如何使用函数读取.txt文件,但我只是想不通如何从相关路径读取它。基本上,这就是我构造项目目录的方式:
project/
| ebin/
| priv/
| include/
| src/
Run Code Online (Sandbox Code Playgroud)
我所有的.beam文件都位于ebin目录中,我需要打开“ priv /”目录中的.txt文件。
这是我的代码:
from_file(FileName) ->
{ok, Bin} = file:read_file(FileName),
...
Run Code Online (Sandbox Code Playgroud)
当我调用此函数时,我传递了一个字符串:“ / absolute / path / to / project / directory / priv”,但是每次都会出现此错误。
exception error: no match of right hand side value {error,enoent}
in function read_mxm:from_file/1 (src/read_mxm.erl, line 34)
in call from mr_tests:wc/0 (src/mr_tests.erl, line 21)
Run Code Online (Sandbox Code Playgroud)
如果我将.txt文件与从其中调用该函数的.beam文件放在同一文件夹中,那么如果我只是输入文件名“ foo.txt”,则该文件就可以正常工作。
如何使功能从项目的相关路径读取?
如果无法通过这种方式进行操作,那么如何读取与.beam文件位于同一目录下的文件夹中的文件?
例如
project/
| ebin/
| | folder_with_the_doc_that_I_want_to_read/
| priv/
| include/
| src/
Run Code Online (Sandbox Code Playgroud) 我正在我的计算机上运行Ubuntu 14.04,我正在尝试创建一个自定义别名,以便我可以运行ghc(Haskell编译器).我尝试编辑.bash_aliases文件并添加了命令:
alias ghci1 = 'GHC_HOME=$HOME/Development/bin/ghc'
alias ghci2 = 'PATH=$GHC_HOME/bin:${PATH}'
alias ghcis = 'ghci'
Run Code Online (Sandbox Code Playgroud)
这样做的重点是因为我安装了ghc 7.8.3并且每次我想打开ghci我必须写下前两个命令,否则我得到错误,我的计算机上没有安装ghc.
在编辑.bash_aliases文件后打开终端时,我收到消息:
bash: alias: ghci1: not found
bash: alias: =: not found
bash: alias: ghci2: not found
bash: alias: =: not found
bash: alias: ghcis: not found
bash: alias: =: not found
bash: alias: ghci: not found
bash: alias: ghci1: not found
bash: alias: =: not found
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我甚至试过这个命令:
.在〜/ .bashrc
以防万一.bash_aliases文件出现问题但我收到相同的错误消息.
此外,当我输入命令时,alias我得到的结果以及其他别名:
alias GHC_HOME='$HOME/Development/bin/ghc'
alias PATH='$GHC_HOME/bin:${PATH}'
Run Code Online (Sandbox Code Playgroud)
所以我的别名没有得到我分配给他们的名字.有没有办法以某种方式逃避'='字符或其他类似的东西才能使用?
PS我用来安装ghc 7.8.3的指南是这样的:
https://gist.github.com/yantonov/10083524
Run Code Online (Sandbox Code Playgroud)
那么是否有更好的方法来安装ghc 7.8.3,或者我是否以错误的方式分配别名?
谢谢.
haskell ×4
bash ×1
erlang ×1
erlang-shell ×1
file-io ×1
http ×1
hunit ×1
java ×1
jetty ×1
ubuntu-14.04 ×1