Reactive Banana: State monad or not?

I have an interface (WX) which is based on Reactive Banana. Now I have different questions about how to really manage the status: Should I consider the state as the Behavior s that I define in the code? If the state depends on external "events" too, not only related to the GUI would be better considering IORef? Or Can I use State Monad? All the examples I saw till now define the

反应香蕉:国家monad或不?

我有一个基于反应香蕉的界面(WX)。 现在我对如何真正管理状态提出了不同的问题: 我应该将状态视为我在代码中定义的Behavior吗? 如果状态也依赖于外部“事件”,不仅考虑到IORef,与GUI相关会更好吗? 或者我可以使用State Monad吗? 直到现在我看到的所有例子都定义了IO环境中的网络。 有没有任何意义的State Monad和如何? 随着Moment ? 我应该将状态视为我在代码中定义的行为吗? 对于大多数场景,您确实需要

An obscure corner of the Haskell Report

Section 5.2 of the Haskell 2010 Report deals with module export lists. At one point, it says: Entities in an export list may be named as follows: A value, field name, or class method, whether declared in the module body or imported, may be named by giving the name of the value as a qvarid, which must be in scope. Operators should be enclosed in parentheses to turn them into qvarids. ...

哈斯克尔报告中一个不起眼的角落

Haskell 2010报告的第5.2节涉及模块导出列表。 它曾说过: 出口清单中的实体可以命名如下: 无论是在模块主体中声明还是导入,值,字段名称或类方法都可以通过将值的名称作为qvarid进行命名,该值必须在作用域中。 运算符应该用括号括起来以将它们变成qvarids。 ... 但是,呃...我错过了什么? 因为根据第10章中的语法参考: qvarid→[monid。 ] varid varid→(small {small | large | digit |'}) 那么在

tagless encoding of mutually recursive types

I am trying to express a pair of mutually recursive data types in the final-tagless encoding. I am able to write: {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE ExplicitForAll #-} module Test where class ExprSYM repr where expr :: forall proc. (ProcSYM proc) => proc Int -> repr class ProcSYM repr where varProc :: forall a. String -> repr a intProc :: String

相互递归类型的无标记编码

我试图在final-tagless编码中表达一对相互递归的数据类型。 我可以写: {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE ExplicitForAll #-} module Test where class ExprSYM repr where expr :: forall proc. (ProcSYM proc) => proc Int -> repr class ProcSYM repr where varProc :: forall a. String -> repr a intProc :: String -> repr Int subjectOf :: forall expr. (E

level list '[a,b,c,...] to function a

I have a data family indexed by type-level list, where types in a list correspond to parameters of a data instance. I want to write function that will have different arity and parameters depending on a data instance, so I could use it like synonym for every data instance in the family. {-# LANGUAGE KindSignatures, DataKinds, TypeOperators, TypeFamilies, FlexibleInstances, PolyKind

级别列表'[a,b,c,...]来运行a

我有一个按类型列表索引的数据族,列表中的类型对应于数据实例的参数。 我想写的函数根据数据实例的不同而有不同的参数和参数,所以我可以使用它作为家族中每个数据实例的同义词。 {-# LANGUAGE KindSignatures, DataKinds, TypeOperators, TypeFamilies, FlexibleInstances, PolyKinds #-} module Issue where type family (->>) (l :: [*]) (y :: *) :: * where '[] ->> y = y (x

Automatic derivation of Data.Vector.Unbox with associated type synonyms

I have a datatype newtype Zq q = Zq (IntType q) where 'q' will be an instance of the class class Foo a where type IntType a and 'IntType' is just the underlying representation (ie Int, Integral, etc) associated with 'q'. I want to make Zq an instance of Data.Vector.Unbox. We are currently manually deriving Unbox using about 50 lines of trivial code as suggested i

使用关联的类型同义词自动推导Data.Vector.Unbox

我有一个数据类型 newtype Zq q = Zq (IntType q) 'q'将成为该类的一个实例 class Foo a where type IntType a 和“IntType”只是与'q'相关的基本表示(即Int,Integral等)。 我想让Zq成为Data.Vector.Unbox的一个实例。 我们目前使用上述链接中建议的约50行简单代码手动推导Unbox。 我们将在代码中制作几种不同类型的“Unbox”,因此为每种类型写50行不具吸引力。 我在这里找到了两个选择。 另一种

Given its body functions, create an instance of a type class (or workaround)

I would like to have a State Monad, where I keep a list of modes. data State = S { modes :: [Mode] } However, I have two requirements: Mode needs to be a parametrized with a type. Mode can be built on run time. Here is how I tried to convince GHC: Attempt 1 , with a data type data Mode a = Mode { complF :: String -> IO [String] action :: State -> String ->

鉴于其主体功能,创建一个类型类的实例(或解决方法)

我想有一个国家Monad,我保留一个模式列表。 data State = S { modes :: [Mode] } 但是,我有两个要求: 模式需要用类型进行参数化。 模式可以在运行时建立。 以下是我试图说服GHC的方式: 尝试1 ,数据类型 data Mode a = Mode { complF :: String -> IO [String] action :: State -> String -> X a } data State a = S { modes :: [Mode a] } initState :: (String -> IO

explanation for "illegal type synonym family"

I'm just curious why I have to write this, instance (HzMonad

对“非法同义词族”的解释

我只是好奇为什么我必须写这个, instance (HzMonad

Print NominalDiffTime as hours, minutes and seconds

I'm surprised nobody has asked this before, but... How do I trivially print a NominalDiffTime as hours, minutes and seconds? (And possibly days, if it happens to be that long...) For reasons unknown, the Show instance prints total seconds, which is obviously useless. (How long is 13,055.22 seconds? Is that a few minutes? A day? Half an hour? I have no idea!) There's the FormatTime c

以小时,分钟和秒为单位打印NominalDiffTime

我很惊讶之前没有人问过这个问题,但是......我如何NominalDiffTime打印NominalDiffTime小时,分钟和秒钟? (可能几天,如果碰巧那么长...) 出于未知原因, Show实例打印总秒数,这显然是无用的。 (13555.22秒,几分钟?一天?半小时?我不知道!) 有FormatTime类,但它不适用于NominalDiffTime 。 看来你可以使用floor方法将总秒数作为实际数字,但是你怎么处理它呢? 据我所知, DiffTime也无济于事。 必须有

switching workspaces with mouse buttons 6 and 7

I would like to be able to move to the previous and next workspaces using the buttons 6 and 7 (the rocker buttons either side of the wheel) on my mouse. I'm guessing it has something to do with additionalMouseBindings , and if that followed the same pattern as additionalKeys I'd be golden. Alas, it is not, and I don't fully understand how to define a new binding. The naive: `addit

使用鼠标按钮6和7切换工作区

我希望能够使用鼠标上的按钮6和7(车轮两侧的摇臂按钮)移动到上一个和下一个工作区。 我猜它是与additionalMouseBindings ,如果随后的相同的模式additionalKeys我会金。 唉,它不是,我不完全理解如何定义一个新的绑定。 天真: `additionalMouseBindings` [ -- get the middle button to switch views ((0, button6), spawn "xdotool key super+Down") , ((0, button7), spawn "xdotool key super+Up") ] 没有工作,原

level computations using type families?

Based on the article in the Monad Reader, Issue #8, I've coded up the type-level solution to the "Instant Insanity" puzzle using both Functional Dependencies and Type Families: fundeps solution: http://lpaste.net/113108 type family solution: http://lpaste.net/113113 The fundeps solutions takes about 200 secs. whereas the type families version completes in about 800 secs. Ar

使用类型族进行级别计算?

根据Monad Reader的第8期文章,我使用函数依赖和类型系列对“即时疯狂”难题进行了类型级解决方案编码: fundeps解决方案:http://lpaste.net/113108 类型家庭解决方案:http://lpaste.net/113113 fundeps解决方案大约需要200秒。 而类型系列版本在大约800秒内完成。 有没有什么技术可以让我的家族版更有效地运行? 我已经为您的两个片段添加了main的以下定义,以便解决方案显示在类型错误消息中,抱怨缺少Show实例: