STM with fclabels

I built a small game engine to manage a board of squares (currently used for playing a Conway's game of life). All the data is accessed throught lenses from fclabels and State. The engine couples user input and graphic rendering (usual game loop). The computations between frames can sometimes be slow and long to execute. So I would like to use concurrency to manage the squares, using STM

STM与fclabels

我建立了一个小型游戏引擎来管理一块广场(目前用于播放康威的生活游戏)。 所有的数据都可以通过fclabels和State的镜头进行访问。 引擎结合用户输入和图形渲染(通常的游戏循环)。 帧之间的计算有时可能很慢并且需要很长时间才能执行。 所以我想使用并发性来管理广场,使用STM的TVar。 我的数据目前是这样表示的: data World = World { … -- window configuration, not important , _squares :: TVar [Square]

Separating State for a Model and GUI IO ( Wx) : Stack or FRP?

For my diagramming tool, I'd like to keep the code of the core model isolated from the GUI. In the following example, the "state " is passed around with vDiag , which is a Tvar . This is a design decision in wx. Now, For my diagramming tool, I 'd like the core model to be "stored" in a fgl Graph, (with complex types in it), and wx will be given only a view on it;

分离模型和GUI IO(Wx)的状态:堆栈还是FRP?

对于我的图表工具,我想保持核心模型的代码与GUI隔离。 在下面的例子中,“状态”被传递周围vDiag ,这是一个Tvar 。 这是wx中的一个设计决定。 现在,对于我的图表工具,我希望将核心模型“存储”在一个fgl图形中(其中包含复杂的类型),并且wx将仅被赋予一个视图; 在这个例子中说,绘画时读取访问点的列表,以及点击,拖动等时写入的一些函数。 我首先想到了一些Monad堆栈,但即使将StateT和来自wx的IO组合起来看起来也不是

traversal tree with Lens and Zippers

I'm learning the Lens package. I must say it's a rather challenging task. Can someone show me how to traverse a Tree with Zipper from Lens? In particular, how can I write a function that takes a list of roots and allows me to access the branches of the sub-tree? Suppose I have this tree. If my input is [1, 3] , the function should allow me access node 10 and 11. import Control.Len

透镜和拉链的遍历树

我正在学习镜头套件。 我必须说这是一项颇具挑战性的任务。 有人可以告诉我如何从镜头穿过拉链树吗? 特别是,我该如何编写一个函数,该函数需要一个根的列表并允许我访问子树的分支? 假设我有这棵树。 如果我的输入是[1, 3] ,该函数应该允许我访问节点10和11。 import Control.Lens import Data.Tree import Data.Tree.Lens testTree = Node 1 [ Node 2 [ Node 4 [ Node 6 [], Node 8 [] ],

Maintaining complex state in Haskell

Suppose you're building a fairly large simulation in Haskell. There are many different types of entities whose attributes update as the simulation progresses. Let's say, for the sake of example, that your entities are called Monkeys, Elephants, Bears, etc.. What is your preferred method for maintaining these entities' states? The first and most obvious approach I thought of was

在Haskell中维护复杂的状态

假设你正在Haskell中构建一个相当大的模拟。 有许多不同类型的实体,其属性随着模拟的进展而更新。 比方说,为了举例,你的实体被称为猴子,大象,熊等。 您维护这些实体的状态的首选方法是什么? 我想到的第一个也是最明显的方法是这样的: mainLoop :: [Monkey] -> [Elephant] -> [Bear] -> String mainLoop monkeys elephants bears = let monkeys' = updateMonkeys monkeys elephants' = updateE

choosing a monad at runtime

I'm trying to write a two-player game in Haskell, such as checkers. I envision having types GameState , Move , and a function result :: GameState -> Move -> GameState that defines the game rules. I want to have both human and automated players, and I figured I'd do this by having a typeclass: class Player p m | p -> m where selectMove :: p -> GameState -> m Move where

在运行时选择一个monad

我正在尝试在Haskell中编写双人游戏,例如跳棋。 我设想有类型GameState , Move和一个函数result :: GameState -> Move -> GameState来定义游戏规则。 我想同时拥有人类和自动播放器,并且我想通过使用类型类来做到这一点: class Player p m | p -> m where selectMove :: p -> GameState -> m Move 其中的想法是,m可以是基本AI玩家的身份,人类的IO,保持移动状态的AI的状态等等。问题是如何从这些到整

How do you structure a stateful module in Haskell?

I'm looking to write a generic module that allows Haskell programs to interact with Cassandra. The module will need to maintain its own state. For example, it will have a connection pool and a list of callbacks to be invoked when a new record is saved. How should I structure the code so that this module can maintain its state? Here are some of the approaches I've been considering. Am

你如何构建Haskell中的有状态模块?

我正在寻找一个允许Haskell程序与Cassandra进行交互的通用模块。 该模块将需要保持自己的状态。 例如,它将有一个连接池和一个保存新记录时调用的回调列表。 我应该如何构造代码以便该模块能够保持其状态? 以下是我一直在考虑的一些方法。 我在正确的轨道上吗? (我是Haskell的新手,仍然在学习从功能上思考的最佳方法。) 选项1: 该模块在(StateT IO)monad中运行,其中s是使用Cassandra模块的整个程序的全局状态

Agents in Haskell or functional languages?

I'm architecturing a Multi Agent System (MAS) framework to describe Beliefs-Desires-Intents (BDI) agents in Haskell (ie agents are concurrent, communicating monadic actions). I searched on the web throughly but I wasn't able to find any reference on similar works, apart from a technical report of an unfinished work, Specifying and Controlling Agents in Haskell. Do you know about any e

Haskell中的代理或函数式语言?

我正在构建一个多Agent系统(MAS)框架来描述Haskell中的Beliefs-Desires-Intents(BDI)代理(即代理是并发的,传递一元行为)。 我在网上搜索过,但除了关于未完成工作的技术报告,Haskell中的指定和控制代理之外,我无法找到任何类似作品的参考。 您是否了解有关BDI代理的任何现有实施或研究报告,可以使用Haskell或其他功能语言来定义? 我的目标是找到可能的相关作品,所有这些都可以管理用功能语言编写的并发智能代理

INLINE Pragma in combination with type classes

Given the following code (copied from the attoparsec library) what does the inline pragma do? I suppose it makes sense for only fmapR to be inlined, but not the other fmap s which are defined in other Functor instances. instance Functor (IResult t) where fmap = fmapR {-# INLINE fmap #-} The inline pragma will copy the contents of the function (in this case fmapR ) to the location where

INLINE Pragma与类型类相结合

鉴于以下代码(从attoparsec库复制而来)内联编译指示可以做什么? 我认为只有fmapR是内联的,而不是其他Functor实例中定义的其他fmap 。 instance Functor (IResult t) where fmap = fmapR {-# INLINE fmap #-} 如果编译器可以证明正在使用的函子是IResult ,则inline编译指示将把函数的内容(在本例中为fmapR )复制到调用它的位置。 在以下情况下,函数不能内联,因为fmap的定义是未知的: f :: Functor f =>

Creating a Haskell application with a .NET GUI

I'd like to create a Haskell app with a .NET gui. I'd like to use cabal as my build tool to take advantage of it's package management etc. I think the Haskell part should be the executable that calls into the .NET code as: This avoids having to manually initialize the Haskell RTC as described here: http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/win32-dlls.html cabal canno

用.NET GUI创建一个Haskell应用程序

我想用.NET gui创建一个Haskell应用程序。 我想使用cabal作为我的构建工具来利用它的包管理等。我认为Haskell部分应该是调用.NET代码的可执行文件,如下所示: 这避免了必须手动初始化Haskell RTC,如下所述:http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/win32-dl​​ls.html cabal无法轻松生成Windows dlls:http://www.haskell.org/haskellwiki/Cabal/Developer-FAQ#Building_DLLs__with_Cabal 我发现创建一

Maybe coalescing operator

I'm wondering how I could go about defining an operator / if an operator already exists in Haskell that lets pick the first Maybe type that isn't Nothing , and if all if them are nothing, it returns some default. Basically something like this: let x = a ?? b ?? c ?? 1 where (??) is the operator and a, b, c are all Maybe types. I'd expect this code to return the first value that is

也许合并运营商

我想知道如何才能定义一个运算符/如果Haskell中已经存在一个运算符,它允许选择第一个不是Nothing Maybe类型,如果它们全都是Nothing ,它将返回一些默认值。 基本上是这样的: let x = a ?? b ?? c ?? 1 其中(??)是运算符, a, b, c都是Maybe类型。 我希望这段代码返回的第一个值是Just或1如果a, b, c都是Nothing 。 我基本上希望复制与您在C#或其他语言中找到的空合并运算符相同的功能。 这个问题展示了如何在F#中完