小编Uli*_*ler的帖子

解决GHC'我发现符号的重复定义......'

当运行Haskell程序导入几个这样的包时:

import Text.Feed.Import 
import Network.HTTP

main = do
        page <- simpleHTTP (getRequest "http://stackoverflow.com")
        print $ page
Run Code Online (Sandbox Code Playgroud)

我得到一个像这样的错误(注意:这个问题打算解决一般问题,这个具体案例只是一个例子):

GHCi runtime linker: fatal error: I found a duplicate definition for symbol get_current_timezone_seconds
whilst processing object file
   /usr/lib/ghc/time-1.4.0.1/HStime-1.4.0.1.o
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
     loaded twice.
GHCi cannot safely …
Run Code Online (Sandbox Code Playgroud)

haskell ghc cabal

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

令人惊讶的子串行为

我在使用Substring方法时遇到了这种行为:

static void Main(string[] args) {
    string test = "123";
    for (int i = 0; true; i++) {
        try {
            Console.WriteLine("\"{0}\".Substring({1}) is \"{2}\"", test, i, test.Substring(i));
        } catch (ArgumentOutOfRangeException e) {
            Console.WriteLine("\"{0}\".Substring({1}) threw an exception.", test, i);
                break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

"123".Substring(0) is "123"
"123".Substring(1) is "23"
"123".Substring(2) is "3"
"123".Substring(3) is ""
"123".Substring(4) threw an exception.
Run Code Online (Sandbox Code Playgroud)

"123".Substring(3)返回一个空字符串,"123".Substring(4)抛出异常.然而,"123"[3]和"123"[4]都是出界的.这在MSDN上记录,但我很难理解为什么以这种方式编写Substring方法.我希望任何越界索引要么总是导致异常,要么总是导致空字符串.任何见解?

c# string

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

在Python中遍历列表时删除元素

在Java中我可以通过使用a Iterator然后使用.remove()迭代器的方法来删除迭代器返回的最后一个元素,如下所示:

import java.util.*;

public class ConcurrentMod {
    public static void main(String[] args) {
        List<String> colors = new ArrayList<String>(Arrays.asList("red", "green", "blue", "purple"));
        for (Iterator<String> it = colors.iterator(); it.hasNext(); ) {
            String color = it.next();
            System.out.println(color);
            if (color.equals("green"))
                it.remove();
        }
        System.out.println("At the end, colors = " + colors);
    }
}

/* Outputs:
red
green
blue
purple
At the end, colors = [red, blue, purple]
*/
Run Code Online (Sandbox Code Playgroud)

我将如何在Python中执行此操作?我在for循环中迭代它时无法修改列表,因为它会导致跳过东西(参见此处).并且似乎没有相当于IteratorJava 的接口.

python iterator loops list python-datamodel

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

函数像catMaybes,但计算Nothing值

我有一个这样的列表:

let foo = [Just 1, Just 2, Nothing, Just 3, Nothing, Nothing]
Run Code Online (Sandbox Code Playgroud)

通过使用catMaybes我只能提取Just构造的值:

catMaybes foo -- [1,2,3]
Run Code Online (Sandbox Code Playgroud)

我现在正在寻找一个函数,它不仅可以生成一个Justs 列表,还可以Nothing通过遍历它来获得有限列表的s 计数.它应该有这样的签名:

catMaybesCount :: [Maybe a] -> ([a], Int)
Run Code Online (Sandbox Code Playgroud)

注意:此问题已回答Q&A风格,因此故意不会显示任何研究工作!

haskell list maybe

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

在lua中获取字符串的第一个字符

假设我在lua中有一个字符串:

> s = "abc123"
Run Code Online (Sandbox Code Playgroud)

我想得到的s1只是s的第一个字符,如果s是空的则为空.

我试过用了

> s1 = s[1]
Run Code Online (Sandbox Code Playgroud)

> s1 = s[0]
Run Code Online (Sandbox Code Playgroud)

如何在不使用外部Lua库的情况下获取第一个字符

但两人都只回来了nil.

lua

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

SCONS运行目标

我一直在寻找,看着,我无法找到我的问题的答案.我今晚刚刚开始学习scons,它看起来很棒!我虽然遇到了一点混乱.

为了便于开发,我经常喜欢让我的make文件构建我的目标,然后运行它以便我可以通过一次击键测试更改.这在make文件中非常简单:

run: $(exe)
    chmod a+x $(exe)
    $(exe)
Run Code Online (Sandbox Code Playgroud)

我已经发现我可以使用子进程这样做:

import subprocess import os.path

env = Environment();
result = env.Program(target = "FOO", source = "BAR");
location = os.path.abspath(result[0].name)
subprocess.call([location])
Run Code Online (Sandbox Code Playgroud)

但是这个解决方案存在问题.就我的实验而言,scons不会等到你的程序在启动子进程调用之前完成构建,所以你最终运行旧的可执行文件,或者如果它是干净后的构建则出错.

scons

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

使用urllib2进行多处理无用?

我最近尝试加速一个小工具(使用urllib2向多处理模块发送请求到(非官方)twitter-button-count-url(> 2000 urls)并解析它的结果)(并且它工人池).我在这里阅读了几个关于多线程的讨论(与标准的非线程版本相比减慢了整个过程)和多处理,但我找不到一个(可能非常简单)问题的答案:

你可以通过多处理加速网址调用,还是像网络适配器这样的瓶颈?我不知道urllib2-open-method的哪一部分可以并行化,以及它应该如何工作......

编辑:这是我想要加速的请求和当前的多处理设置:

 urls=["www.foo.bar", "www.bar.foo",...]
 tw_url='http://urls.api.twitter.com/1/urls/count.json?url=%s'

 def getTweets(self,urls):
    for i in urls:
        try:
            self.tw_que=urllib2.urlopen(tw_url %(i))
            self.jsons=json.loads(self.tw_que.read())
            self.tweets.append({'url':i,'date':today,'tweets':self.jsons['count']})
        except ValueError:
            print ....
            continue
    return self.tweets 

 if __name__ == '__main__':
    pool = multiprocessing.Pool(processes=4)            
    result = [pool.apply_async(getTweets(i,)) for i in urls]
    [i.get() for i in result]
Run Code Online (Sandbox Code Playgroud)

python urllib2 multiprocessing gil

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

Classy-Prelude(head.head)

我正试图将几个项目转换成classy-prelude目前.虽然大多数行为对我来说都很简单,但(head . head)在简单的2D列表中给出了神秘的错误.

考虑以下GHCi会话:

Prelude> (head . head) [[1,2],[3,4]]
1
Run Code Online (Sandbox Code Playgroud)

让我们试试这个用ghci -XNoImplicitPreludeclassy-prelude:

> import ClassyPrelude
ClassyPrelude> (head . head) [[1,2],[3,4]]

<interactive>:10:1:
    Couldn't match type `MinLen (Succ nat1) mono1' with `[[t0]]'
    Expected type: [[t0]] -> Element mono0
      Actual type: MinLen (Succ nat1) mono1 -> Element mono0
    The function `head . head' is applied to one argument,
    but its type `MinLen (Succ nat1) mono1 -> Element mono0'
    has only one
    In the expression: (head …
Run Code Online (Sandbox Code Playgroud)

haskell classy-prelude

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

Warp:绑定到Unix域套接字

此处列出的示例代码显示了如何仅在特定主机上进行warp侦听.

此外,这篇文章展示了一些关于如何在Haskell中使用unix域套接字的基础知识.

我如何结合这两种方法,以使warp监听(即绑定)特定的unix域套接字(比方说warp.sock)?

注意:这个问题故意没有研究,因为它回答了Q&A-Style.

haskell unix-socket haskell-warp

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

bitbucket无法合并无关分支

我在bitbucket上有存储库(比如说A)和分叉存储库A-dev.一切都运作良好3个月.但是最近,当我试图在A-dev中创建pull请求时,它说:

无法合并无关分支

为什么会发生这种情况以及如何解决?无论如何要排除故障吗?

谢谢. 编辑 错误的屏幕截图

git bitbucket

8
推荐指数
3
解决办法
2万
查看次数