在Haskell的并行和并发编程中,Simon Marlow提供了Stream a基于以下数据,以及一些生产者和消费者:
data IList a
= Nil
| Cons a (IVar (IList a))
type Stream a = IVar (IList a)
streamFromList :: NFData a => [a] -> Par (Stream a)
streamFromList xs = do
var <- new
fork $ loop xs var
return var
where
loop [] var = put var Nil
loop (x:xs) var = do
tail <- new
put var (Cons x tail)
loop xs tail
Run Code Online (Sandbox Code Playgroud)
后来,他提到了这种方法的缺点并提出了一个解决方案:
在我们之前的例子中,消费者比生产者更快.相反,如果生产者比消费者更快,那么就没有什么可以阻止生产者在消费者面前走很长的路并在内存中建立一个长的IList链.这是不可取的,因为大型堆数据结构由于垃圾收集而产生开销,因此我们可能希望对生产者进行速率限制以避免它过早地进行.有一个技巧可以为流API添加一些自动速率限制.它需要在
IList类型中添加另一个构造函数:Run Code Online (Sandbox Code Playgroud)data IList a = …
我purescript通过nodejs以下命令序列成功运行了纸浆的helloworld :
$ pulp init
...
$ pulp run
* Building project in /data/works/beta_projects/js_games/processing/hello-ps
* Build successful.
Hello sailor!
Run Code Online (Sandbox Code Playgroud)
接下来,我想Hello sailor!通过在div内部文本中注入消息来使消息在正文中显示
<html>
<body>
<div id="output" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我需要做什么?
我尝试使用pulp server命令并获得空白页,http://localhost:1337/而无需提供index.html任何信息,并且控制台中没有任何消息。
有pulp browserify一条命令可以打印出我希望包含在index.html的script标签中的javascript的命令,但是我不知道我需要在哪里放置index.html文件。
可能是什么原因missing module?
$ nix-shell -p haskellPackages.ghc -p haskellPackages.random\nRun Code Online (Sandbox Code Playgroud)\n\n给出以下外壳
\n\n[nix-shell:~]$ ghci \nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\nLoaded GHCi configuration from /data/works/dotfiles/ghci\nPrelude> import System.Random\n\n<no location info>: error:\n Could not find module \xe2\x80\x98System.Random\xe2\x80\x99\n It is not a module in the current program, or in any known package.\nRun Code Online (Sandbox Code Playgroud)\n\nHaskell 软件包的安装和使用方法是什么?nix
我以为nixos.haskellPackages.<package>会自动注册 ghc 但似乎并非如此。
重新装上random内壳,还是不行。
[nix-shell:~]$ nix-env -iA nixos.haskellPackages.random\ninstalling \xe2\x80\x98random-1.1\xe2\x80\x99\n\n[nix-shell:~]$ ghc-pkg list | grep -i random\nRun Code Online (Sandbox Code Playgroud)\n 有时在运行时nix-build,nixos-rebuild我发现了一些易于修复的问题(例如已弃用的警告或多余的导入),我想“很有趣,我可以在空闲时间修复它”。
我知道我可以将构建日志重定向到一个文件,但我一直忘记这样做,直到我再次看到警告。
问题:nix 构建守护进程是否将构建日志保存在某处?
在LYAHFGG中,有一章说该列表定义为:
data List a = Cons a (List a) deriving (Show, Read, Eq, Ord)
Run Code Online (Sandbox Code Playgroud)
我理解除了缺点之外,大多数这意味着什么.当我尝试:t Cons并:i Cons在ghci我得到一个不在范围错误.在本章后面,它还讨论了: - 和它与Cons的相同之处
infixr 5 :-:
data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
Run Code Online (Sandbox Code Playgroud)
但我真的不明白这:-:意味着什么.
在另一个资源中,在有关数据类型的部分中,它们定义以下数据类型:
data Expr = X
| Const Int
| Expr :+: Expr
| Expr :-: Expr
| Expr :*: Expr
| Expr :/: Expr
| IfZero Expr Expr Expr
deriving (Eq, Ord) …Run Code Online (Sandbox Code Playgroud) 有没有办法从默认的'%'更改IPython魔术函数前缀?我在ipython_config.py中找不到任何选项
由于我使用的是vim和ghci,我(不知何故)训练自己将':'作为命令前缀.
当我想调用魔术函数并自动为每个IPython魔术函数调用前缀':'时,这非常烦人,例如:cd,:ed和:load
我用map (:[])分裂String来[[Char]],不知道是否有做同样的任何内建的功能存在
In [1]: as = "abcdefg"
In [2]: bs = map (:[]) as
print bs
["a","b","c","d","e","f","g"]
In [3]: import Control.Monad
cs = join bs
print cs
"abcdefg"
Run Code Online (Sandbox Code Playgroud)
这个地图很容易理解,但是,我觉得unjoin . join = id应该存在但是没有在搜索中找到它[a] -> [[a]]
我在我的vimrc中有这些:
if has("autocmd")
augroup Misc
" Jump to the last known position when reopening a file
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
augroup FTOptions
autocmd!
autocmd FileType cpp,java setlocal commentstring=//\ %s
autocmd FileType markdown setlocal textwidth=78 formatprg=par\ -w78
augroup END
Run Code Online (Sandbox Code Playgroud)
在markdown文件中,我想使用par进行格式化.它运行良好,但如果系统上没有安装"par",我会收到警告.我想知道是否有办法检查并且只在安装par时设置"formatprg = par\-78",否则使用VIM的默认格式.
我会很感激任何建议.
我正在Haskell中处理一个函数,它接收Ints和Int的列表.
sublistSum :: [Ints] -> Int -> [[Ints]]
Run Code Online (Sandbox Code Playgroud)
它返回的是一个子列表,其中包含原始列表中与Int相加的数字列表.
例如:
sublistSums [1, 5, -2, 4, 3, 2] 2
[[1,-2,3],[-2,4],[2]]
Run Code Online (Sandbox Code Playgroud)
我的工作:
sublistSums [] num = []
sublistSums (x:xs) num
| findSum x xs num == num = findSum x xs num 0 : sublistSums (x:xs) num
| otherwise = sublistSums xs num
findSum x [] num count = []
findSum x (y:ys) num count
| ...
Run Code Online (Sandbox Code Playgroud)
所以findSum我做的辅助函数应该返回这样的数字列表(加起来这个数字).
到目前为止我有点困惑.我如何标记它以便findSum不会反复给我相同的数字列表?
假设我想在光标位置运行grep.我会做yiw,然后ctrl-r "在命令窗口(后:grep)使用.
使用较少的击键将单词发送到命令窗口的更快捷方式是什么?
给出(来自Haskell Amuse Bouche Lectures)
module Part2a where
data List ? = EndOfList
| Link ? (List ?)
deriving Show -- makes printing out results possible
Run Code Online (Sandbox Code Playgroud)
用法示例:
empty = EndOfList
oneWord = Link "apple" EndOfList
twoWords = Link "banana" (Link "cantaloupe" EndOfList)
Run Code Online (Sandbox Code Playgroud)
问题:"链接"功能在哪里定义?
我到处搜索,找不到它.