小编Bil*_*nde的帖子

如何在haskell中展平列表列表

我想做的只是我要问的.函数的类型签名应该是这样的:

flatten::[[[Int]]] -> [[Int]]
Run Code Online (Sandbox Code Playgroud)

我试图搜索一些扁平的代码,但他们定义了新的类型,这让我感到困惑.有帮助吗?提前致谢.

haskell flatten

6
推荐指数
2
解决办法
4815
查看次数

在VHDL中找到运算符"+"的'0'定义

首先,我想指出这是我第一次用VHDL尝试,所以要善良.我想读取X1 ... X4输入并在输出端产生1的总和.这是我的代码

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity counter_of_aces is 
  Generic(N: integer := 3);
     port( X1, X2, X3, X4 : IN BIT; 
        count: out std_logic_vector(N-1 downto 0)); 
end counter_of_aces;

architecture behavioral of counter_of_aces is 
signal counter : std_logic_vector(?-1 downto 0);
begin 
  process (X1, X2, X3, X4) 
  begin
    counter <= "0";
    if(X1='1' OR X2='1' OR X3='1' OR X4='1')then 
        counter <= counter + "1"; --O counter ?????????? ?? ???????? ?????? 
    else
        counter <= counter;
    end if; 
  end process; 
end behavioral;
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

ERROR:HDLCompiler:69 …
Run Code Online (Sandbox Code Playgroud)

vhdl

5
推荐指数
2
解决办法
4万
查看次数

const char的多重定义*

我得到了全局的上述消息链接器错误

const char* HOST_NAME = "127.0.0.1";
Run Code Online (Sandbox Code Playgroud)

我不认为我已经编译了两次文件,但这里是我对文件的定义.

main.cpp中

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include "connection.hpp"
Run Code Online (Sandbox Code Playgroud)

connection.cpp

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "connection.hpp"
Run Code Online (Sandbox Code Playgroud)

connection.hpp

#ifndef __connection__
#define __connection__
#include <unistd.h>
#include <netinet/in.h>

const int BUFFSIZE = sysconf(_SC_PAGESIZE);             //Define page size
const char* HOST_NAME = "127.0.0.1";                    //Local host
//Definition of a class
#endif
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

c++ linker-errors multiple-definition-error

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

如何在unix中替换文件的字符串

经过一番谷歌搜索后,我发现 sed 命令就是我所需要的。但说实话,这个命令的标志似乎无法理解。我想要做的就是用另一个文件替换单引号字符串。word1、word2 等等都不是单/双引号的。例子:

之前:foo.txt

word1 word2 word3 'This the text that needs replacement' word4 word5
Run Code Online (Sandbox Code Playgroud)

之后:foo.txt

word1 word2 word3 'I have been replaced' word4 word5
Run Code Online (Sandbox Code Playgroud)

请注意,文本“这是需要替换的文本”不是恒定的,其内容可能会有所不同。

unix sed

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

我怎样才能处理"发生检查:无法构造无限类型:a0 = [a0]"?

码:

myperms [] = [[]]
myperms xs = [a:ys| a<-xs, ys<-(delete a xs)]
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

project2.hs:66:15:
     Occurs check: cannot construct the infinite type: a0 = [a0]
     In the second argument of `(:)', namely `ys'
     In the expression: a : ys
     In the expression: [a : ys | a <- xs, ys <- (delete a xs)]
Run Code Online (Sandbox Code Playgroud)

我想不出这个错误.有人可以向我解释如何处理这些情况,以免出错并编写更好的代码吗?提前致谢.

haskell

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

如何删除haskell中列表的子列表

我需要的只是以下内容

deletesub:: [Int]->[Int]->[Int]
Run Code Online (Sandbox Code Playgroud)

例如,

deletesub [2,1,4] [3,1,32,5,2,43,7,4] = [3,32,5,43,7]
Run Code Online (Sandbox Code Playgroud)

我在hoogle使用签名搜索但没有搜索:/

haskell list sublist

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

将列表转换为元组,同时转换列表中的列表

在Python中将列表转换为元组的简单方法是:

tuple1=tuple(list1)
Run Code Online (Sandbox Code Playgroud)

但是如果list1包含一个或多个列表,它们将保持不变.有没有办法可以转换它们?例如

list1=[1,3,'abc',[3,4,5]]
Run Code Online (Sandbox Code Playgroud)

去:

tuple1=(1,3,'abc',(3,4,5))
Run Code Online (Sandbox Code Playgroud)

python tuples list type-conversion

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

在haskell中按顺序列出的子列表

我想做的只是非常简单,但我似乎很难实现.我希望haskell中的函数具有此行为.

orderedsubs [2,5,3,4] = [[],[2],[2,5],[2,5,3],[2,5,3,4]]
Run Code Online (Sandbox Code Playgroud)

最初我考虑删除最后一个元素并将其放入列表并使用先前创建的列表重复该过程,但一旦存储,它就消失了.我不在乎子列表的顺序是否不同,但我想要这些特定的子列表.那么,有什么想法吗?提前致谢.

haskell sublist

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

警告:赋值从整数中生成指针,而没有在malloc处进行强制转换[默认情况下启用]

90: if (links->info[links->length-1].paths = malloc(connections*sizeof(char*))==NULL) {
        perror("Malloc failed! Aborting execution\n"); exit(MF);}
for (j=0; j<connections; j++) {
93:    if (links->info[links->length-1].paths[j] = malloc(250*sizeof(char))==NULL) {
    perror("Malloc failed! Aborting execution\n"); exit(MF);}
}
Run Code Online (Sandbox Code Playgroud)

哪里

 Link *links;
 int connections;
 typedef struct{               //Info of the link
   int inode;                  //I-node
   int prime_inode;            //Corresponding i-node
   int connections;            //Number of hard links
   int next_path;              //Where to put the next path
   char **paths;               //Paths that refer to the i-node
  } Link_info;

typedef struct {
   int length;                 //Number of links
   Link_info *info; …
Run Code Online (Sandbox Code Playgroud)

c malloc compiler-warnings

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