Here is a simple example where the identity Functor works well: newtype R a = R a instance Functor R where fmap f (R a) = R $ f a but if I add an intermediate type family, things get wonky: data IntT data a :-> b type family Sem a :: * type instance Sem IntT = Int type instance Sem (a :-> b) = Sem a -> Sem b newtype S a = S (Sem a) and now I can't make S int
以下是一个简单的例子,其中身份证明函数运作良好: newtype R a = R a instance Functor R where fmap f (R a) = R $ f a 但如果我添加一个中间类型的家庭,事情会变得糟糕: data IntT data a :-> b type family Sem a :: * type instance Sem IntT = Int type instance Sem (a :-> b) = Sem a -> Sem b newtype S a = S (Sem a) 现在我不能让S变成一个Functor。 我可以很容易地定义一类
I'm looking for a way to deploy a Haskell web application on a low-spec toy server. The server specs: OS: debian stable (squeeze) i386 CPU: 1 GHz Pentium IV RAM: 512 MB Storage: 512 MB compact flash (mounted on /var ), 4 GB USB compact flash (mounted on / ) The server runs fine, it doesn't see much traffic (it's mainly used by myself, friends and family members), and I can
我正在寻找一种在低规格玩具服务器上部署Haskell Web应用程序的方法。 服务器规格: OS:debian stable(挤压)i386 CPU:1 GHz Pentium IV RAM:512 MB 存储:512 MB闪存(安装在/var ),4 GB USB闪存(安装在/ ) 服务器运行正常,但没有看到太多流量(主要由我自己,朋友和家人使用),并且我可以在起居室运行它,因为它完全静音并且功耗非常低(大约10 W空闲,40瓦峰值)。 很明显,我想避免安装整个Haskell平
The page Foldr Foldl Foldl' discusses foldl' , and defines it like: foldl' f z [] = z foldl' f z (x:xs) = let z' = z `f` x in seq z' $ foldl' f z' xs This is done to avoid space leaks, ie so fold' that produces a constant size result only uses constant space. However, this doesn't necessarily work, as pointed out here: The involved seq function does
页面Foldr Foldl Foldl'讨论foldl' ,并将其定义为: foldl' f z [] = z foldl' f z (x:xs) = let z' = z `f` x in seq z' $ foldl' f z' xs 这样做是为了避免空间泄漏,即fold'产生恒定大小的结果只使用恒定的空间。 但是,这并不一定有效,正如这里所指出的那样: 涉及的seq函数只评估最顶层的构造函数。 如果累加器是一个更复杂的对象,那么fold'仍然会建立未经评估的thunk
I have a function that returns vector<MyClass> ; what's the best way to change this into something FFI-appropriate? I'm thinking a type like :: [CIntPointer] might be a nice compromise, if possible to obtain. You could define your own C functions to alloc, free, insert, remove, etc. These functions can wrap the C++ container you want to access. For example: extern "C" { Obj
我有一个函数返回vector<MyClass> ; 把这个变成适合FFI的最好方法是什么? 我:: [CIntPointer]一个类型:: [CIntPointer]可能是一个很好的妥协,如果可能获得。 你可以定义你自己的C函数来分配,释放,插入,删除等。这些函数可以包装你想要访问的C ++容器。 例如: extern "C" { Obj * obj_create() { return new Obj(); } void obj_destroy(Obj * schema) { delete obj; obj = NULL; } ... ... } 然后在F
I really like Repa 's interface, even regardless of its concurrency capabilities. And I actually need repa's arrays to be sequential, since my arrays are relatively small ones and parallelization on them is useless, even harmful. However I do use parallelization in my program with parallel-io, so I compile it -threaded and run with +RTS -Nx . And this enables parallelization for repa.
即使不考虑其并发能力,我也非常喜欢Repa的界面。 实际上我需要repa的数组是连续的,因为我的数组相对较小,并且对它们的并行化是无用的,甚至是有害的。 不过,我使用并行在我与并行IO程序,所以我编译-threaded与运行+RTS -Nx 。 这使得并行化可以进行修复。 有没有办法关闭repa的并发功能? 嗯,在写这篇文章的时候,我知道我不太可能需要DIM1以外的其他东西,所以也许我应该切换到Vector 。 但是,这个问题的答案是
Inspired by Brent Yorgey's adventure game, I've been writing a small text based adventure game (a la Zork) that uses the MonadPrompt library. It's been fairly straightforward to use it to separate the IO backend from the actual function that governs gameplay, but I'm now trying to do something a bit more complicated with it. Basically, I want to enable undo and redo as a featur
受Brent Yorgey冒险游戏的启发,我一直在编写一个使用MonadPrompt库的小型文本冒险游戏(la Zork)。 使用它将IO后端与管理游戏玩法的实际功能分开是相当直接的,但我现在试图做一些更复杂的事情。 基本上,我想启用撤消和重做作为游戏的一个功能。 我的策略是保持游戏状态的拉链(包括最后输入的内容)。 由于我希望能够在重新加载游戏时保持历史记录,保存文件只是玩家执行的所有可能影响游戏状态的输入列表(因此检查库
When doing calculations modulo n with large numbers, you will encounter huge performency penalties when doing for example mod (123456789^987654321) n . Instead you have to use your own ^ that internally calculates mod n also for intermedite calculations. Sure, I can easily implement my own functions, but then I have to explicitly say "mod n" for each operation. Instead one could bui
当以大数字进行模n计算时,例如mod (123456789^987654321) n时会遇到巨大的执行惩罚。 相反,你必须使用你自己的^在内部计算mod n也用于中间计算。 当然,我可以很容易地实现我自己的功能,但是我必须为每个操作明确地说出“mod n”。 相反,可以构建一个数值表达式树并推迟实际计算,并且在最后状态模n只能进行一次。 (请参阅下面的我的代码) 我从这开始就清楚地表明了我的意思,但是我想知道是否已经存在这样的实现,它
So I know this is a kind of a large topic, but I need to accept a chunk of text, and extract the most interesting keywords from it. The text comes from TV captions, so the subject can range from news to sports to pop culture references. It is possible to provide the type of show the text came from. I have an idea to match the text against a dictionary of terms I know to be interesting somehow
所以我知道这是一个很大的话题,但我需要接受大量的文本,并从中提取最有趣的关键字。 文字来自电视字幕,所以主题可以从新闻到体育到流行文化参考。 可以提供文本来自的显示类型。 我有一个想法,将文本与我知道有趣的术语字典进行匹配。 Haskell的哪些库可以帮助我? 假设我确实有一个有趣词汇的词典和一个数据库来存储它们,有没有一种特别的方法可以推荐在文本中匹配关键词? 有没有一种明显的方法我没有想到?
I've seen the term Free Monad pop up every now and then for some time, but everyone just seems to use/discuss them without giving an explanation of what they are. So: what are free monads? (I'd say I'm familiar with monads and the Haskell basics, but have only a very rough knowledge of category theory.) Edward Kmett's answer is obviously great. But, it is a bit technical. He
我已经看到Free Monad这个术语偶尔会弹出一段时间,但似乎每个人似乎都会使用/讨论它们,而没有给出它们的解释。 那么,什么是免费单子? (我会说我熟悉单子和Haskell的基础知识,但对类别理论只有非常粗略的理解。) 爱德华Kmett的答案显然很棒。 但是,这有点技术性。 这可能是一个更容易理解的解释。 自由monads只是将函数转化为monad的一般方法。 也就是说,给定任意函数f Free f是一个monad。 这不会很有用,除
Possible Duplicate: What is a monad? How would you describe a monad in non-programming terms? Is there some concept/thing outside of programming (outside of all programming, not just FP) which could be said to act or be monad-like in a significant way? Here's my current stab at it: Monads are bucket brigades: Each operation is a person standing in line; ie there's an unambiguo
可能重复: 什么是monad? 你如何用非编程术语来描述monad? 编程之外还有一些概念/东西(除了所有的编程之外,不仅仅是FP)可以说是采取行动还是以一种重要的方式呈现monad? 这是我目前的刺伤: Monad是水桶旅: 每项行动都是排队的人; 即有一个明确的操作发生顺序。 每个人需要一个桶作为输入,从中取出一些东西,并将新东西放入桶中。 反过来,桶又传递给旅中的下一个人(通过绑定或>>=操作)。 retu