Megaparsec, backtracking user state with StateT and ParsecT

Using Megaparsec 5. Following this guide, I can achieve a back-tracking user-state by combining StateT and ParsecT (non-defined types should be obvious/irrelevant): type MyParser a = StateT UserState (ParsecT Dec T.Text Identity) a if I run a parser p :: MyParser a , like this: parsed = runParser (runStateT p initialUserState) "" input The type of parsed is: Either (ParseError Char Dec) (a,

Megaparsec,用StateT和ParsecT回溯用户状态

使用Megaparsec 5.遵循本指南,我可以通过组合StateT和ParsecT (非定义类型应该是显而易见的/不相关的)来实现反向跟踪用户状态: type MyParser a = StateT UserState (ParsecT Dec T.Text Identity) a 如果我运行解析器p :: MyParser a ,就像这样: parsed = runParser (runStateT p initialUserState) "" input parsed的类型是: Either (ParseError Char Dec) (a, UserState) 这意味着,如果出现错误,用户状态将丢

How can I run xmonad on a nomachine remote desktop?

I'm trying to configure a NoMachine remote desktop to run xmonad. One thing I keep running into is that the default xmonad installation instructions require logging out and logging back in. In a remote desktop app like NoMachine, there's no way to log out as a user -- only disconnect from the session. I have the option to create a new Gnome, KDM, or XDM desktop, or a custom session whi

我如何在nomachine远程桌面上运行xmonad?

我正在尝试配置NoMachine远程桌面来运行xmonad。 我不断遇到的一个问题是,默认的xmonad安装说明需要注销并重新登录。在NoMachine等远程桌面应用程序中,无法以用户身份注销 - 只能从会话中断开连接。 我可以选择创建一个新的Gnome,KDM或XDM桌面,也可以选择自定义会话,它可以在启动时执行默认X客户端脚本或自定义命令等操作。 有没有人有如何最好地配置这个经验? 如果你只想运行一个简单的xmonad会话(而不是,例如,使

Analog of free monads for Profunctors

We can define data Free fa = Pure a | Free (f (Free fa)) data Free fa = Pure a | Free (f (Free fa)) and so have Functor f => Monad (Free f) . If we define data T fab = R a | S b | T (fa (T fab)) data T fab = R a | S b | T (fa (T fab)) data T fab = R a | S b | T (fa (T fab)) have we some analogous M so Profunctor f => M (T fa) , where class Profunctor f where dimap :: (a -> b) -> (

Profunctors的免费monads模拟

我们可以定义data Free fa = Pure a | Free (f (Free fa)) data Free fa = Pure a | Free (f (Free fa)) ,所以Functor f => Monad (Free f) 。 如果我们定义data T fab = R a | S b | T (fa (T fab)) data T fab = R a | S b | T (fa (T fab)) data T fab = R a | S b | T (fa (T fab))有我们一些类似的M所以Profunctor f => M (T fa) ,其中class Profunctor f where dimap :: (a -> b) -> (c -> d) ->

Abusing the algebra of algebraic data types

The 'algebraic' expression for algebraic data types looks very suggestive to someone with a background in mathematics. Let me try to explain what I mean. Having defined the basic types Product • Union + Singleton X Unit 1 and using the shorthand X² for X•X and 2X for X+X et cetera, we can then define algebraic expressions for eg linked lists data List a = Nil | Cons a (List

滥用代数数据类型的代数

代数数据类型的“代数”表达式对于具有数学背景的人来说非常具有启发性。 让我试着解释我的意思。 定义了基本类型 产品• 联盟+ 辛格尔顿X 单位1 并且使用简写X²代替X•X和2X代替X+X等等,我们可以定义代数表达式,例如链表 data List a = Nil | Cons a (List a) data List a = Nil | Cons a (List a) ↔L L = 1 + X • L 和二叉树: data Tree a = Nil | Branch a (Tree a) (Tree a) data Tree a = Nil | Branch a

Haskell singletons: What do we gain with SNat

I'm trying to grook Haskell singletons. In the paper Dependently Typed Programming with Singletons and in his blog post singletons v0.9 Released! Richard Eisenberg defines the data type Nat which defines natural numbers with the peano axioms: data Nat = Zero | Succ Nat By using the language extension DataKinds this data type is promoted to the type level. The data constuctors Zero and S

哈斯克尔单身人士:我们从SNat获得什么

我正在尝试追查哈斯克尔的单身人士。 在论文中依赖类型化编程单身人士和在他的博客文章singletons v0.9发布! Richard Eisenberg定义了用peano公理定义自然数的数据类型Nat: data Nat = Zero | Succ Nat 通过使用语言扩展DataKinds,该数据类型被提升为类型级别。 数据构造器Zero和Succ被提升为类型构造器的“零”和“Succ”。 有了这个,我们可以为每个自然数获得一个类型级别上唯一且唯一的对应类型。 例如,对于3,我们

'Kind' of confused about forall in type

I've run into an odd situation in GHC 8.0.1 with kind-indexed (?) GADTs where introducing foralls in the type vs kind signatures produces different type-checking behaviors. Consider the following data types: {-# LANGUAGE TypeInType, GADTs, ExplicitForAll #-} -- Same thing happens when we replace ExplicitForAll with ScopedTypeVariables import Data.Kind data F (k :: * -> *) where data

对'类型'的迷惑

我在GHC 8.0.1中遇到了一种奇怪的情况,它使用了kind-indexed(?)GADT,其中在类型签名和类签名中引入了多个类,产生了不同的类型检查行为。 考虑以下数据类型: {-# LANGUAGE TypeInType, GADTs, ExplicitForAll #-} -- Same thing happens when we replace ExplicitForAll with ScopedTypeVariables import Data.Kind data F (k :: * -> *) where data G :: F k -> * where G :: G x 这种数据类型编译得很好

Liberal coverage condition introduced in GHC 7.7 breaks code valid in GHC 7.6

The idea I'm writing a DSL, which compiles to Haskell. Users of this language can define own immutable data structures and associated functions. By associated function I mean a function, which belongs to a data structure. For example, user can write (in "pythonic" pseudocode): data Vector a: x,y,z :: a def method1(self, x): return x (which is equivalent to the foll

GHC 7.7中引入的自由覆盖条件在GHC 7.6中有效

这个想法 我正在编写一个编译为Haskell的DSL。 这种语言的用户可以定义自己的不可变数据结构和相关功能。 通过关联函数,我指的是一个属于数据结构的函数。 例如,用户可以编写(在“pythonic”伪代码中): data Vector a: x,y,z :: a def method1(self, x): return x (相当于下面的代码,但是也显示了相关函数beheva就像开放世界假设的类型类): data Vector a: x,y,z :: a def Vector.method1(self, x):

Haskell could not unify type instance equations

I am trying to tag canonical Nat datatype with (Even/Odd) Parity kind to see if we can get any free theorems. Here is the code: {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} -- Use DataKind promotion with type function for even-odd module EvenOdd where data Parity = Even | Odd -- Parity is promoted to kind level Parity. -- Even & Odd to type level

Haskell无法统一类型​​实例方程

我试图用(偶/奇)奇偶类标记规范的Nat数据类型,看看我们是否可以得到任何自由定理。 代码如下: {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} -- Use DataKind promotion with type function for even-odd module EvenOdd where data Parity = Even | Odd -- Parity is promoted to kind level Parity. -- Even & Odd to type level 'Even & 'Odd of kind Parity -

How to use the comparison in GHC.TypeLits

I ran into problems playing with GHC.TypeLits. Consider the following GADT: data Foo :: Nat -> * where SmallFoo :: (n <= 2) => Foo n BigFoo :: (3 <= n) => Foo n My understanding was, that now for every n , the type Foo n is populated by exactly one value (which is either a SmallFoo or a BigFoo depending on the value of n ). But if I now want to construct a concrete ins

如何使用GHC.TypeLits中的比较

我遇到了使用GHC.TypeLits的问题。 考虑下面的GADT: data Foo :: Nat -> * where SmallFoo :: (n <= 2) => Foo n BigFoo :: (3 <= n) => Foo n 我的理解是,现在对于每一个n ,类型Foo n都由一个值填充(这是一个SmallFoo或一个BigFoo,取决于n的值)。 但是如果我现在想要构造一个具体的实例如下: myFoo :: Foo 4 myFoo = BigFoo 然后GHC(7.6.2)吐出以下错误消息: No instance for (3 <=

Illegal polymorphic or qualified type using RankNTypes and TypeFamilies

I've been slowly working on porting the llvm package to use data kinds, type families and type-nats and ran into a minor issue when trying to remove the two newtypes used for classifying values ( ConstValue and Value ) by introducing a new Value type parameterized by its constness. CallArgs only accepts Value 'Variable a arguments and provides a function for casting a Value 'Const a

使用RankNTypes和TypeFamilies的非法多态或限定类型

我一直在努力移植llvm包以使用数据类型,类型族和类型nats,并试图通过引入新的Value类型来移除用于对值进行分类的两个新类型( ConstValue和Value )时遇到小问题用其常量进行参数化。 CallArgs只接受Value 'Variable a参数并提供一个函数来将Value 'Const a转换为Value 'Variable a 。 我想推广CallArgs来允许每个参数是'Const 'Variable或'Variable 。 这可能使用类型族以某种方式进行编码吗?