helkell frege中的hello world:
hello.fr:
module Hello where
main args = do
putStrLn "Hello, World!"
此代码生成hello.java:
/*
Source code is in UTF-8 encoding. The following symbols may appear, among others:
α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω « • ¦ » ∀ ∃ ∷ … → ← fi fl ƒ
If you can't read this, you're out of luck. This code was generated with the frege compiler version 3.24.80
from hello.fr Do not edit this file! Instead, edit the source file and recompile.
*/
import frege.run8.Func;
import frege.run8.Lazy;
import frege.run8.Thunk;
import frege.run.Kind;
import frege.run.RunTM;
import frege.runtime.Meta;
import frege.runtime.Phantom.RealWorld;
import frege.Prelude;
import frege.control.Category;
import frege.control.Semigroupoid;
import frege.java.IO;
import frege.java.Lang;
import frege.java.Util;
import frege.java.util.Regex;
import frege.prelude.Maybe;
import frege.prelude.PreludeArrays;
import frege.prelude.PreludeBase;
import frege.prelude.PreludeIO;
import frege.prelude.PreludeList;
import frege.prelude.PreludeMonad;
import frege.prelude.PreludeText;
@SuppressWarnings("unused")
@Meta.FregePackage(
source="hello.fr", time=1470398249962L, jmajor=1, jminor=8,
imps={
"frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase", "frege.prelude.PreludeIO",
"frege.prelude.PreludeList", "frege.prelude.PreludeMonad", "frege.prelude.PreludeText", "frege.java.util.Regex"
},
nmss={"Prelude", "PreludeArrays", "PreludeBase", "PreludeIO", "PreludeList", "PreludeMonad", "PreludeText", "Regexp"},
symas={}, symcs={}, symis={}, symts={},
symvs={@Meta.SymV(offset=20, name=@Meta.QName(pack="Hello", base="main"), stri="s(u)", sig=1, depth=1, rkind=49)},
symls={},
taus={
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="[]")}),
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="StringJ")}),
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="Char")}),
@Meta.Tau(kind=0, suba=1, subb=2), @Meta.Tau(kind=0, suba=0, subb=3),
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="ST")}),
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="RealWorld")}),
@Meta.Tau(kind=0, suba=5, subb=6),
@Meta.Tau(kind=2, suba=0, tcon={@Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="()")}),
@Meta.Tau(kind=0, suba=7, subb=8)
},
rhos={@Meta.Rho(rhofun=false, rhotau=4), @Meta.Rho(rhofun=false, rhotau=9), @Meta.Rho(sigma=0, rhotau=1)},
sigmas={@Meta.Sigma(rho=0), @Meta.Sigma(rho=2)}, exprs={@Meta.Expr()}
)
final public class Hello {
final public static Func.U<RealWorld, Short> $main(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return Prelude.putStrLn("Hello, World!");
}
public static void main(final java.lang.String[] argv) {
try {
frege.run.RunTM.argv = argv;
PreludeBase.TST.<Short>performUnsafe($main
(Thunk.lazy(PreludeArrays.IListSource_JArray.<String/*<Character>*/>toList(argv)))
).call();
frege.runtime.Runtime.stdout.get().close();
frege.runtime.Runtime.stderr.get().close();
} finally { frege.run.Concurrent.shutDownIfExists(); }
}
}
然后我编译生成的java代码,没有错误:
javac -cp frege3.jar build/Hello.class
然后我尝试运行代码:
cd build
java Hello
但这会返回错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: frege/run8/Lazy
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: frege.run8.Lazy
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
如何在jvm上运行生成的frege java代码?
我正在使用java8
答案 0 :(得分:4)
启动命令时,您还需要在类路径中添加frege3.jar
,请尝试以下操作:
java -cp .:frege3.jar Hello
假设frege3.jar
和Hello.class
都在当前目录中
答案 1 :(得分:0)