我正在尝试在运行 Ubuntu 子系统的 Windows 笔记本电脑上安装 GHC 和 ghcup。我不断收到同样的错误,我什至不知道出了什么问题。以下是错误消息:
[ Info ] verifying digest of: ghc-8.10.7-x86_64-fedora27-linux.tar.xz
[ Info ] Unpacking: ghc-8.10.7-x86_64-fedora27-linux.tar.xz to /tmp/ghcup-61d1fb5776edc19e
[ Info ] Installing GHC (this may take a while)
[ ghc-make ] # on Win64, "install -s" calls a strip that doesn't understand 64bit binaries.
[ ghc-make ] # For some reason, this means the DLLs end up non-executable, which means
[ ghc-make ] "utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" copy compiler stage2 "strip" '' '/home/levi...
i... Installing library in /home/levi/.ghcup/ghc/8.10.7/lib/ghc-8.10.7/ghc-8.10.7
i... …Run Code Online (Sandbox Code Playgroud) 我正在通过J.Gibbons教授对Haskell中类似APL的编程进行扩展抽象.我坚持Applicative为hypercuboid数据类型定义实例,尽管该文件指出它是完全可行的.简化示例如下.
{-# LANGUAGE KindSignatures, GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, DataKinds #-}
import Control.Applicative
import Data.Traversable (Traversable)
class (Applicative f, Traversable f) => Dim f
class Shapely (fs :: [* -> *])
instance Shapely '[]
instance (Dim f, Shapely fs) => Shapely (f ': fs)
-------------------------------------
-- Hypercuboid datatype
-------------------------------------
data Hyper :: [* -> *] -> * -> * where
Scalar :: a -> Hyper '[] a
Prism :: (Dim f, Shapely fs) …Run Code Online (Sandbox Code Playgroud) 我有以下"主"模板:
template <
template <typename> class S
> struct TT { /*...*/ };
Run Code Online (Sandbox Code Playgroud)
和我想要使用的模板TT:
template <int N, typename T> struct S1 {};
Run Code Online (Sandbox Code Playgroud)
特别是,我想使用类似的东西
TT< S1<5> > t2; // "Invalid template arguments" here
Run Code Online (Sandbox Code Playgroud)
它是模板的一种部分应用.我知道Boost.MPL涉及这种东西.问题是我已经有一些使用TT和模板的代码了
template <typename T> struct S2 {}; // S3, S4…
Run Code Online (Sandbox Code Playgroud)
它被送到TT.
所以,问题是:我怎么能使用S1与TT具有最小的修改现有的代码.如果必须使用Boost.MPL,请告诉我最合适的解决方案.
我有以下Java代码:
String s2 = "SUM 12 32 42";
Pattern pat1 = Pattern.compile("(PROD)|(SUM)(\\s+(\\d+))+");
Matcher m = pat1.matcher(s2);
System.out.println(m.matches());
System.out.println(m.groupCount());
for (int i = 1; i <= m.groupCount(); ++i) {
System.out.println(m.group(i));
}
Run Code Online (Sandbox Code Playgroud)
产生:
true
4
null
SUM
42
42
Run Code Online (Sandbox Code Playgroud)
我想知道是什么null,为什么12和32都不见了(我希望在群体中找到它们).
我正在尝试使用这种代码:
trait Outer {
type Inner
def f(x:Inner) : Void
}
object test {
def apply(o: Outer, i : Outer#Inner) : Void =
o.f(i)
}
Run Code Online (Sandbox Code Playgroud)
我在最后一行中出错了:
类型不匹配; 发现:i.type(底层类型为Outer#Inner)需要:o.Inner
如果我将apply的签名更改为
def apply(o: Outer, i : o.Inner) : Void
Run Code Online (Sandbox Code Playgroud)
然后我收到一个错误:
非法依赖方法类型
是否可以使这段代码工作?
我有几个类,其中一个继续引用其他的对象:
class Inner {};
class Outer {
Inner & in;
public:
Outer(Inner & in) : in(in) {}
};
Run Code Online (Sandbox Code Playgroud)
如果我必须从const引用到Inner创建外部对象怎么办?为了这个,我是否必须为OuterConst写特定的课程?
UPD:使用模板的任何简洁解决方案?为了避免在OuterConst类中重复代码.
UPD2:当Inner没有const时,它应该是可修改的(所以我不能在当前的Outer实现中将const添加到Inner成员).