小编use*_*850的帖子

实例声明中的非法类型签名

我在实例声明错误中得到非法类型签名,我不知道为什么它会弹出我的程序.缩进似乎是对的,等等.我希望你能帮助我.

class Game g s | g -> s where
  findPossibleMoves :: Player -> g -> [(s,g)]
  identifyWinner :: g -> Player -> Maybe Player

instance Game HForest HStrategy where
  identifyWinner :: HForest -> Player -> Maybe Player
  identifyWinner ts p = getWinner $ getLeaves ts

  findPossibleMoves :: Player -> HForest -> [(HStrategy, HForest)]
  findPossibleMoves p ts = map (\s -> (s,move s ts)) $ getStrategies p ts
Run Code Online (Sandbox Code Playgroud)

错误是:

Illegal type signature in instance declaration:
  findPossibleMoves :: Player -> HForest …
Run Code Online (Sandbox Code Playgroud)

haskell ghc

10
推荐指数
1
解决办法
2837
查看次数

Java:名称相同但泛型类型不同

我想为我的代码使用ArrayList,但它应该包含不同类型的对象.所以它应该是这样的:

 switch (foo) {
        case "foo1":
            list=new ArrayList<foo1>();
            break;
        case "foo2":
            list = new ArrayList<foo2>();
            break;
Run Code Online (Sandbox Code Playgroud)

我知道发布的代码不起作用,但有可能使类似的东西.

在你问之前,应该在这个List上执行多个动作,但是我不会再用List的不同名称再写一遍.

public class foo1 {}

public class foo2 {}

    import java.util.ArrayList;
public class work{
    public static void main(String[] args){
    ArrayList<?> list;
     switch (args[0]) {
            case "foo1":
                list=new ArrayList<foo1>();
                break;
            case "foo2":
                 list= new ArrayList<foo2>();
                break;
            default:
                System.out.println("Some Error Text");
                return;

        }
     list.add(new foo1());
    }
}
Run Code Online (Sandbox Code Playgroud)

java generics types

2
推荐指数
1
解决办法
72
查看次数

Haskell从String中删除Chars

我正在尝试编写表单的函数

f :: String -> [String]
f str = ...
Run Code Online (Sandbox Code Playgroud)

返回通过从中删除一个字符而形成的所有字符串的列表str.例如:

ghci> f "stack"
["tack","sack","stck","stak","stac"]
Run Code Online (Sandbox Code Playgroud)

因为String并且[Char]是同义词,我可以使用索引,但我知道你应该避免在Haskell中这样做.除了使用索引之外还有更好的方法吗?

string haskell char

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

根据单元格值从Pandas DataFrame中删除行

如何根据单元格值删除Pandas Dataframe中的行而不提供特定的列名?

例如:

我有这个DataFrame,我想删除一个单元格包含值'd'的所有行.

   A B C D
1  1 2 d 5
2  1 3 4 0
3  d 2 1 2
4  3 2 1 7
Run Code Online (Sandbox Code Playgroud)

所以我最终得到了DataFrame

  A B C D
2 1 3 4 0
4 3 2 1 7
Run Code Online (Sandbox Code Playgroud)

有办法实现这个吗?我的谷歌技能只找到了需要特定列名称的解决方案.

python dataframe pandas

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

标签 统计

haskell ×2

char ×1

dataframe ×1

generics ×1

ghc ×1

java ×1

pandas ×1

python ×1

string ×1

types ×1