Data families vs Injective type families

Now that we have injective type families, is there any remaining use case for using data families over type families? Looking at past StackOverflow questions about data families, there is this question from a couple years ago discussing the difference between type families and data families, and this answer about use cases of data families. Both say that the injectivity of data families is the

数据族vs内射型家族

既然我们有内射类型族,那么在类型族中使用数据族还有什么用例吗? 回顾过去关于数据族的StackOverflow问题,几年前有一个问题讨论类型族和数据族之间的区别,以及关于数据族用例的这个答案。 两者都表示数据家族的注入是他们最大的优势。 查看数据族的文档,我发现不应该使用内射类族重写数据族的所有用途。 例如,假设我有一个数据族(我已经合并了文档中的一些示例,试图挤压数据族的所有功能) data family G a b dat

level constraints in instances of type families

Is it possible to have type synonym families for parametrized data such as Data.Param.FSVec? Ideally, I would like this to compile: class A e where type Arg e a f :: (Arg e a -> b) -> e a -> e b instance A X where type Arg X a = Nat size => FSVec size a f = {- implementation -} I have tried several workarounds, like wrapping FSVec size a in a newtype, or constraint synony

类型家族情况下的级别约束

Data.Param.FSVec参数化数据有可能具有类型同义词族吗? 理想情况下,我希望这样编译: class A e where type Arg e a f :: (Arg e a -> b) -> e a -> e b instance A X where type Arg X a = Nat size => FSVec size a f = {- implementation -} 我已经尝试了几种解决方法,比如在新类型中包装FSVec size a或约束同义词,但似乎我无法获得任何合理的权利。 上下文+最小工作示例 A是先前定义的类(

Are applicative transformers really superfluous?

There is a lot of talk about Applicative not needing its own transformer class, like this: class AppTrans t where liftA :: Applicative f => f a -> t f a But I can define applicative transformers that don't seem to be compositions of applicatives! For example sideeffectful streams: data MStream f a = MStream (f (a, MStream f a)) Lifting just performs the side effect at every ste

应用变压器是否真的是多余的?

有很多关于Applicative不需要自己的变压器类的讨论,如下所示: class AppTrans t where liftA :: Applicative f => f a -> t f a 但是我可以定义应用变形金刚似乎不是应用的组成! 例如副作用的流: data MStream f a = MStream (f (a, MStream f a)) 提升只是在每一步都会产生副作用: instance AppTrans MStream where liftA action = MStream $ (,) <$> action <*> pure (liftA action) 如

Can I constrain a type family?

In this recent answer of mine, I happened to crack open this old chestnut (a program so old, half of it was written in the seventeenth century by Leibniz and written on a computer in the seventies by my dad). I'll leave out the modern bit to save space. class Differentiable f where type D f :: * -> * newtype K a x = K a newtype I x = I x data (f :+: g) x = L (f x)

我可以限制类型家庭吗?

在我最近的这个回答中,我碰巧揭开了这个老栗子(一个很古老的程序,其中一半是由莱布尼茨在十七世纪写成的,七十年代由我父亲写在计算机上)。 为了节省空间,我会省略现代的一点。 class Differentiable f where type D f :: * -> * newtype K a x = K a newtype I x = I x data (f :+: g) x = L (f x) | R (g x) data (f :*: g) x = f x :&: g x instance Differentiable (K

Partially lift with liftIO

I'm trying to do something that's probably impossible. I have a type that is an instance of MonadIO . If you liftIO an IO action in a context where this type is the base monad of some transformer stack, it will work fine. So, what I'd like to be able to do is take a value that's already been lifted part-way (to my type) and lift it "the rest of the way" in one step.

升降机部分升降

我正在尝试做一些可能不可能的事情。 我有一个类型是MonadIO一个实例。 如果在这种类型是某些变压器堆栈的基本单元的上下文中liftIO IO操作,则它将正常工作。 所以,我希望能够做到的是取得一个已经被部分取消的价值(以我的方式),并一举解除它的“其余部分”。 我可以用两种方法做到这一点。 一个是我的类型实际上可以重新嵌入到正常的IO中,所以我可以这样做: liftMore :: (MonadIO m) => MyType a -> m a liftM

fd, monadLib, and the paradox of choice

Hackage has several packages for monad transformers: mtl: Monad transformer library transformers: Concrete functor and monad transformers monads-fd: Monad classes, using functional dependencies monads-tf: Monad classes, using type families monadLib: A collection of monad transformers. mtl-tf: Monad transformer library using type families. mmtl: Modular Monad transformer library mt

fd,monadLib和选择的悖论

Hackage提供了几个适用于monad变压器的软件包: mtl:Monad变压器库 变形金刚:混凝土仿真器和单体变压器 monads-fd:Monad类,使用函数依赖关系 monads-tf:Monad类,使用类型族 monadLib:monad变换器的集合。 mtl-tf:使用类型族的Monad变换器库。 mmtl:模块化Monad变压器库 mtlx:带有类型索引的Monad变换器库,提供'免费'副本。 compose-trans:可组合的单体变压器 (也许我错过了一些) 我

Mapping between GADTs

I'm relatively new to Haskell, and am using it to write a compiler, using Alex and Happy. The language I'm writing it for is whitespace sensitive: blocks are delimited by indentation, and lines are continued by an increase of two indentation levels. Although I've been down this road with Alex's monadUserState wrapper, as someone unfamiliar with monads I found this approach quit

GADT之间的映射

我对Haskell比较陌生,正在使用它编写一个编译器,使用Alex和Happy。 我为它写的语言是空白敏感的:块由缩进分隔,并且行继续增加两个缩进级别。 虽然我一直在用Alex的monadUserState包装器走这条路,但作为一个不熟悉monad的人,我发现这种方法非常混乱。 因此,我在考虑不是将lexing过程分成两个阶段,一个是扫描令牌,另一个是用缩进,缩进和延续令牌替换原始空白(这种方法可能性能较差,但我是在这个阶段不关心表现)。

How do Happy and Alex bootstrap themselves into being?

The source tree for happy contains AttrGrammarParser.ly and Parser.ly and the source tree for alex contains Scan.x . Yet, as far as I can tell in order to compile happy , we need to transform the .ly files into .lhs files using... happy , and in order to compile alex we need to transform the .x files into .hs files using... alex . So it seems like there must be some bootstrapping going on here

Happy和Alex如何引导自己成为自己?

happy的源代码树包含AttrGrammarParser.ly和Parser.ly , alex的源代码树包含Scan.x 然而,据我所知,为了编译happy ,我们需要使用... happy地将.ly文件转换成.lhs文件,为了编译alex我们需要将.x文件转换成.hs文件使用... alex 。 因此,为了编译任何工具,似乎必须有一些引导进行。 每个项目的Setup.lhs文件都包含一些模板扩展,但据我所知,不要执行任何特别的操作来执行引导。 引导程序如何以及在哪里完成? 我看

How to specify tab width for Alex lexer?

Alex documentation (Chapter 5) says: You might want Alex to keep track of the line and column number in the input text, or you might wish to do it yourself (perhaps you use a different tab width from the standard 8-columns, for example) But changing tab width from 8 to 4 in Alex position tracker is rather hard than easy. The code for this is hidden deep inside Alex generated routines: -- th

如何为Alex lexer指定制表符宽度?

Alex文档(第5章)说: 您可能希望Alex记录输入文本中的行和列号,或者您可能希望自己完成它(例如,可能使用与标准8列不同的制表符宽度) 但是,在Alex位置跟踪器中将标签宽度从8更改为4比较容易。 这个代码隐藏在Alex生成的例程中: -- this function is used by `alexGetByte`, which is used by `alex_scan_tkn`, which is -- used by `alexScanUser` and `alexRightContext`, -- which is used by `alex_accept` etc

error in wrapper template

I'm trying to understand Alex and lexers in general but I'm having trouble to run my lexer. I wrote lexers in "basic" and "posn" wrappers but I couldn't in "monad" wrapper. I think I have to use monad wrapper because I need to collect strings and token positions in input. I also need multiple states. For now I'm trying to run this simple exmaple:

包装模板中的错误

我试图理解亚历克斯和词法分析器,但是我无法运行词法分析器。 我写了“基本”和“封装”封装的词法分析器,但是我不能使用“monad”封装。 我想我必须使用monad包装器,因为我需要在输入中收集字符串和标记位置。 我也需要多个国家。 现在我试图运行这个简单的例子: { module Main (main) where } %wrapper "monad" $whitespace = [ btnfvr] $digit = 0-9 $alpha = [a-zA-Z_] $upper = [A-Z] $lower = [a