由于编译器更容易内联函数,因此函数显然更有效,并且它们在参数化方面的工作效果更好.什么时候应该使用普通的旧函数而不是函子?
我是Haskell的新手,并尝试制作拼字游戏解算器.它接收您当前拥有的字母,查找它们的所有排列并过滤掉那些字典单词.代码非常简单:
import Data.List
main = do
dict <- readFile "words"
letters <- getLine
let dictWords = words dict
let perms = permutations letters
print [x | x <- perms, x `elem` dictWords]
Run Code Online (Sandbox Code Playgroud)
然而,与我使用Python的非常类似的实现相比,它的速度非常慢.有什么根本我做错了吗?
*编辑:这是我的Python代码:
from itertools import permutations
letters = raw_input("please enter your letters (without spaces): ")
d = open('words')
dictionary = [line.rstrip('\n') for line in d.readlines()]
d.close()
perms = ["".join(p) for p in permutations(letters)]
validWords = []
for p in perms:
if p in dictionary: validWords.append(p)
for validWord in …
Run Code Online (Sandbox Code Playgroud) 在 C++ 中,是否可以将类成员变量标记为 extern?
我能有......吗
class Foo {
public:
extern string A;
};
Run Code Online (Sandbox Code Playgroud)
字符串 A 在我包含的另一个头文件中定义的位置?
是否有一些我可以执行的JavaScript代码滚动到Facebook上消息框的顶部?因此,当您单击"查看全部"并转到主消息页面时,如果向上滚动则会加载更多消息.我想强制它继续向上滚动以继续加载消息.我试过了
document.body.scrollTop = document.documentElement.scrollTop = 0;
但那当然只滚动到实际页面的顶部.有关如何滚动消息框的任何想法?
c++ ×2
c++11 ×2
extern ×1
facebook ×1
haskell ×1
javascript ×1
optimization ×1
python ×1
scroll ×1