只是寻找解释以下组成如何工作:
(=<<) . return
Run Code Online (Sandbox Code Playgroud)
哪里
(=<<) :: (a -> m b) -> m a -> m b
return :: a -> m a
(.) :: (b -> c) -> (a -> b) -> a -> c
Run Code Online (Sandbox Code Playgroud)
最终类型:
GHCi> :t (=<<) . return
(=<<) . return :: Monad m => m b -> m a -> m b
Run Code Online (Sandbox Code Playgroud)
我上无法掌握如何能比得上马用(A - > MB) ,即.如何将一个简单类型的返回结果应用到期望函数类型的(= <<)的第一个参数?
monads haskell type-inference function-composition reader-monad
让我们想象一下以下简化的Django项目:
<root>/lib/python2.7/site-packages/externalapp/shop
<root>/myapp
Run Code Online (Sandbox Code Playgroud)
myapp还externalapp.shop.models通过添加几个字段来扩展模型.manage.py makemigrations确实生成了名为0004_auto_20150410_2001.py的模式迁移文件:
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
# __init__ is added by me as an attempt how to tell django's
# migration loader operations are for the different application
def __init__(self, name, app_label):
super(Migration, self).__init__(name, 'shop')
dependencies = [
('myapp', '__first__'),
('shop', '0003_auto_20150408_0958'),
]
operations = [
migrations.AddField(
model_name='product',
name='vat',
field=models.ForeignKey(to='myapp.VAT', null=True),
),
]
Run Code Online (Sandbox Code Playgroud)
如果<root>/lib/python2.7/site-packages/externalapp/shop/migrations/默认情况下将上述迁移模式放在路径中,manage.py migrate则会正确添加成功和表字段.
但是,如果我确实将上述迁移文件移动到myapp/migrations/,则以下manage.py …
只是试图在ObjectPascal/Delphi中实现C/C++静态局部变量的类似功能.我们在C中有以下功能:
bool update_position(int x, int y)
{
static int dx = pow(-1.0, rand() % 2);
static int dy = pow(-1.0, rand() % 2);
if (x+dx < 0 || x+dx > 640)
dx = -dx;
...
move_object(x+dx, y+dy);
...
}
Run Code Online (Sandbox Code Playgroud)
使用类型常量作为静态变量替换的等效ObjectPascal代码无法编译:
function UpdatePosition(x,y: Integer): Boolean;
const
dx: Integer = Trunc( Power(-1, Random(2)) ); // error E2026
dy: Integer = Trunc( Power(-1, Random(2)) );
begin
if (x+dx < 0) or (x+dx > 640) then
dx := -dx;
...
MoveObject(x+dx, y+dy);
...
end; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用MS XMLHTTP COM检索HTTP文档的内容.我确实复制了以下示例代码,但即使这样也无效,并且在发送方法调用时出现EOLEException错误"访问被拒绝"失败.
uses
MSXML, ComObj, ActiveX;
procedure TForm1.Button1Click(Sender: TObject);
var
httpDoc: XMLHTTP; // IXMLHTTPRequest
begin
httpDoc := CreateOleObject('MSXML2.XMLHTTP') as XMLHTTP;
try
httpDoc.open('GET', 'http://www.google.com/index.html', False, EmptyParam, EmptyParam);
httpDoc.send(''); // <-- EOLEException 'Access is denied'
if (httpDoc.readyState = 4) and (httpDoc.status = 200) then
ShowMessage(httpDoc.responseText);
finally
httpDoc := nil;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我真的不知道我做错了什么:(
我希望Ruby的解析器可以进行这个简单的优化,但似乎它没有(谈到YARV实现,Ruby 1.9.x,2.0.0):
require 'benchmark'
def fib1
a, b = 0, 1
while b < 9999**4000
a, b = b, a+b
end
puts "\tdone !"
end
MAX_FIB = 9999**4000
def fib2
a, b = 0, 1
while b < MAX_FIB
a, b = b, a+b
end
puts "\tdone !"
end
if __FILE__ == $0
Benchmark.bm do |r|
r.report('plain') { fib1 }
r.report('predefined constant') { fib2 }
end
end
plain done !
32.810000 0.220000 33.030000 ( 33.069854)
predefined constant done !
0.120000 …Run Code Online (Sandbox Code Playgroud) 任何人都可以解释为什么haskell在以下示例中强制执行显式类型签名以及如何修改它以避免需要显式声明?
import qualified Data.List as L
main = do
print $ length $ L.nub [1,1,2,3] -- 3, passed (Eq a, Num a) => [a]
print $ length $ L.nub [] -- ambiguous type error, passed (Eq a) => [a]
-- can help type system with explicit signature but how to avoid ?
print $ length $ L.nub ([] :: [Int])
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,在ghci中以交互方式编写的相同代码没有歧义问题,并且打印零长度:
?> :m +Data.List
?> print $ length $ nub []
0 -- ?? can you explain ??
Run Code Online (Sandbox Code Playgroud)
更新: 看起来甚至同样限制 …
我需要在非gui模式下重新定义Vim的键盘映射.
我根本不明白为什么以下命令不起作用:
:set <M-F5>=^[[15~
"E518: Unknown option: <M-F5>=^[[15~"
Run Code Online (Sandbox Code Playgroud)
而单独F5键或Meta与非功能键的映射确实有效:
:set <F5>=^[[15~
"ok"
:set <M-space>=^[[15~
"ok"
Run Code Online (Sandbox Code Playgroud)
如何用Vim中的功能键F1-F12重新定义Alt/Meta?
Thx提前.
大卫
更新:问题更 正在我的.vimrc中,我有以下键组合映射
autocmd Filetype python noremap <buffer> <silent> <M-F9> :w !pylint -E %<CR>
Run Code Online (Sandbox Code Playgroud)
但它只适用于gVim.遗憾的是,它不适用于非gui版本的Vim,因为Vim接收转义序列"^ [[20~"而不是直接的Meta-F9键码.
zipWith功能有两个严格的版本:
1)非常严格,列表l1和l2的元素得到评估,因此他们的thunk不会占用所有堆栈空间(Don Stewart代码)
zipWith' f l1 l2 = [ f e1 e2 | (e1, e2) <- zipWith k l1 l2 ]
where
k x y = x `seq` y `seq` (x,y)
Run Code Online (Sandbox Code Playgroud)
2)不是很严格,试图通过其他方式强制评估.
zipWith'' f l1 l2 = [ f e1 e2 | (e1, e2) <- zip (map (\x -> x `seq` x) l1) (map (\x -> x `seq` x) l2) ]
Run Code Online (Sandbox Code Playgroud)
问题是:为什么使用map的第二个例子的等效代码不会使函数也严格?
只是好奇如何重写以下函数只在程序的生命周期中调用一次?
getHeader :: FilePath -> IO String
getHeader fn = readFile fn >>= return . take 13
Run Code Online (Sandbox Code Playgroud)
上述功能从各种功能中被多次调用.如果使用相同的参数调用函数,如何防止重新打开文件,即.文件名 ?
寻找一种方法来评估存储在外部文件中的elisp代码并将其结果作为函数参数传递.演示我想要实现的内容的示例如下:
;; content of my_template.el
'(this is a list)
;; content of .emacs where result of my_template.el has to be used
(define-auto-insert "\.ext$"
;; bellow is my attempt to retrieve resulting list object
;; but getting nil instead
(with-temp-buffer
(insert-file-contents ("my_template.el"))
(eval-buffer))))
Run Code Online (Sandbox Code Playgroud)
可能正在寻找一个类似eval的函数,除了副作用之外还返回最后一个表达式的结果.
任何的想法 ?
haskell ×4
delphi ×2
benchmarking ×1
django ×1
django-admin ×1
dot-emacs ×1
elisp ×1
emacs ×1
emacs24 ×1
monads ×1
msxml ×1
optimization ×1
pascal ×1
python ×1
reader-monad ×1
ruby ×1
strictness ×1
vim ×1