Writing "fib" to run in parallel:

I'm learning Haskell and trying write code to execute in parallel, but Haskell always runs it sequentially. And when I execute with the -N2 runtime flag it take more time to execute than if I omit this flag. Here is code: import Control.Parallel import Control.Parallel.Strategies fib :: Int -> Int fib 1 = 1 fib 0 = 1 fib n = fib (n - 1) + fib (n - 2) fib2 :: Int -> Int fib2 n = a

写“fib”并行运行:

我正在学习Haskell并尝试并行执行写代码,但Haskell总是按顺序运行它。 当我使用-N2运行时标志执行时,执行所需的时间比省略此标志要多。 这是代码: import Control.Parallel import Control.Parallel.Strategies fib :: Int -> Int fib 1 = 1 fib 0 = 1 fib n = fib (n - 1) + fib (n - 2) fib2 :: Int -> Int fib2 n = a `par` (b `pseq` (a+b)) where a = fib n b = fib n + 1 fib3 :: Int ->

How to write special characters like new line, and format output of haddock

I would like to format my haddock documentation as I do with javadoc, something like inserting html or any other markup that let me get a cleaner output without uncluding any javascript or CSS... Specially, I would like to know how to insert a line break in the documentation. thanks! Haddock is designed to work with multiple output formats, including LaTeX, so it uses its own markup format in

如何编写像new line这样的特殊字符,并输出haddock的格式

我想格式化我的haddock文档,就像我使用javadoc一样,插入html或任何其他标记,这些标记可以让我得到更清晰的输出,而不必除去任何javascript或CSS ...特别是,我想知道如何插入一行打破文件。 谢谢! Haddock设计用于处理多种输出格式,包括LaTeX,因此它使用自己的标记格式而不是HTML。 我不认为你可以插入一个换行符,但是你可以通过留空行开始一个新的段落,例如 -- | First paragraph. -- -- Second paragraph.

Alpha Beta prune for chess always returning the first move in the list

I am writing a minimax algorithm with alpha-beta pruning for chess and cannot get the algorithm to return anything but the first move that it generates. I have been knocking my head against but cannot figure out what is going wrong. The code is a bit messy and in dire need of refactoring, but maybe you can see something that I am not. I have verified that my evalNaive' function works as e

国际象棋的Alpha Beta修剪总是返回列表中的第一步

我正在写一个用于国际象棋的alpha-beta修剪的minimax算法,并且不能让算法返回任何东西,除了它产生的第一步。 我一直在敲我的头,但无法弄清楚发生了什么问题。 代码有点混乱,迫切需要重构,但也许你可以看到我不是的东西。 我已经证实我的evalNaive功能按预期工作(非常简单,只需根据材料评估板)。 alphaBeta :: Game -> Move alphaBeta g = maxGame $ map (mv -> (abMinNode 4 (-100) 100 (move g mv), mv)) (ne

Using values not from the application monad with Heist templates

I'm trying to write an application server using Happstack, Heist, and web-routes, but am having trouble figuring out how to let splices access values that don't originate from my application's monad stack. There are two situations where this comes up: Parameters extracted from the URL path via web-routes. These come from pattern-matching on a type-safe URL when routing the reques

使用Heist模板中不是来自应用程序monad的值

我试图用Happstack,Heist和web-routes编写一个应用服务器,但在解决如何让拼接访问不是源自我的应用程序的monad堆栈的值时遇到困难。 出现这种情况有两种情况: 通过网络路由从URL路径中提取参数。 当将请求路由到正确的处理程序时,这些来自类型安全URL上的模式匹配。 会话信息。 如果请求是针对全新会话的,则我无法从请求中的cookie中读取会话标识符(因为尚未存在此类cookie),并且如果需要,我无法使用拼接创建新

Coroutine with StateT and ST and IO

having some trouble with a group of monads I'm trying to combine. I'm using monad-coroutine, State and lens (as I have deeply nested state). I had an initial approach where there was a working solution. The main point here is that I can request to execute IO tasks outside of Coroutine. {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE

具有StateT和ST和IO的协程

在我尝试合并的一组monad中遇到一些麻烦。 我使用monad-coroutine,状态和镜头(因为我有深度嵌套状态)。 我有一个初步的方法,有一个工作解决方案。 这里的要点是我可以请求在协程外执行IO任务。 {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE UndecidableInstances #-} module Main where import

Local variables in Template Haskell declarations

I'm reading through pozorvlak's baby steps post on Template Haskell in an attempt to understand it myself, and I came across this section: Recall that we were trying to programmatically produce declarations of the form data Fred = Fred . Let's try it with quasiquoting. Because of the restrictions on calling TH code, we'll have to put it in its own module, so let's put the

模板Haskell声明中的局部变量

我正在阅读模板哈斯克尔的pozorvlak的婴儿步骤帖子,试图自己理解它,并且我遇到了这个部分: 回想一下,我们试图以编程方式生成表单data Fred = Fred声明。 让我们尝试quasiquoting。 由于调用TH代码的限制,我们必须将其放在它自己的模块中,所以让我们将以下内容放在Keyword.hs中,以便编译器可以找到它: module Keyword (keyword) where import Language.Haskell.TH.Syntax keyword name = [d| data $(name) = $(name)

Why does Haskell contain so many equivalent functions

It seems like there are a lot of functions that do the same thing, particularly relating to Monads, Functors, and Applicatives. Examples (from most to least generic): fmap == liftA == liftM (<*>) == ap liftA[2345] == liftM[2345] pure == return (*>) == (>>) An example not directly based on the FAM class tree: fmap == map (I thought there were quite a few more with List, Foldab

为什么Haskell包含如此多的等价函数

似乎有很多功能可以做同样的事情,特别是Monad,Functors和Applicatives。 示例(从最多到最不通用): fmap == liftA == liftM (<*>) == ap liftA[2345] == liftM[2345] pure == return (*>) == (>>) 不直接基于FAM类树的示例: fmap == map (我认为List,Foldable,Traversable还有很多,但它看起来像前一段时间大部分都是更通用的,因为我在旧的堆栈溢出/留言板问题中只看到旧的,不太通用的类型签名)

Haskell threads heap overflow despite only 22Mb total memory usage?

I am trying to parallelize a ray-tracer. This means I have a very long list of small computations. The vanilla program runs on a specific scene in 67.98 seconds and 13 MB of total memory use and 99.2% productivity. In my first attempt I used the parallel strategy parBuffer with a buffer size of 50. I chose parBuffer because it walks through the list only as fast as sparks are consumed, and do

尽管只有22Mb的内存使用量,Haskell线程堆溢出了吗?

我试图平行化射线追踪器。 这意味着我有一个很长的小计算列表。 该香草程序运行在67.98秒的特定场景和13 MB的总内存使用率和99.2%的生产率。 在我的第一次尝试中,我使用了缓冲区大小为50的并行策略parBuffer 。我选择parBuffer是因为它只消耗火花,并且不会像parList那样parList列表的parList ,它会使用因为名单很长,所以很多记忆。 使用-N2 ,运行时间为100.46秒,总内存使用量为14 MB,生产力为97.8%。 火花信息是

Tools for analyzing performance of a Haskell program

While solving some Project Euler Problems to learn Haskell (so currently I'm a completly beginner) I came over Problem 13. I wrote this (naive) solution: --Get Number of Divisors of n numDivs :: Integer -> Integer numDivs n = toInteger $ length [ x | x<-[2.. ((n `quot` 2)+1)], n `rem` x == 0] + 2 --Generate a List of Triangular Values triaList :: [Integer] triaList = [foldr (+) 0 [1.

用于分析Haskell程序性能的工具

在解决一些项目欧拉问题以学习Haskell(所以目前我是一个完全初学者)时,我来到了问题13。我写了这个(天真的)解决方案: --Get Number of Divisors of n numDivs :: Integer -> Integer numDivs n = toInteger $ length [ x | x<-[2.. ((n `quot` 2)+1)], n `rem` x == 0] + 2 --Generate a List of Triangular Values triaList :: [Integer] triaList = [foldr (+) 0 [1..n] | n <- [1..]] --The same recursive

Can't install cairo with cabal on Windows

Configuring cairo-0.12.0... setup.exe: The program pkg-config version >=0.9.0 is required but it could not be found. cabal: Error: some packages failed to install: cairo-0.12.0 failed during the configure step. The exception was: ExitFailure 1 那么我如何才能在windows上获得pkg-config或者如何安装cairo呢? Do you have the cairo development files installed? Recall this isn't the same as havin

在Windows上无法安装cairo

Configuring cairo-0.12.0... setup.exe: The program pkg-config version >=0.9.0 is required but it could not be found. cabal: Error: some packages failed to install: cairo-0.12.0 failed during the configure step. The exception was: ExitFailure 1 那么我如何才能在windows上获得pkg-config或者如何安装cairo呢? 你有没有安装cairo开发文件? 回想一下,这与开发DLL不一样! 请参阅其下载页面的Windows部分