Understanding forall in Monad '>>=' function?

Following this answer, I've implemented a generic lift function in my program: liftTupe :: (x -> c x) -> (a, b) -> (c a, c b) --This will error liftTuple :: (forall x. x -> c x) -> (a, b) -> (c a, c b) I understand, that in this context, forall is enabling x to be of any type ( [] , Maybe etc..). I'm now looking into the definition of >>= in Monads: class Appl

了解Monad'>> ='函数中的所有内容?

在这个答案之后,我在我的程序中实现了一个通用升降功能: liftTupe :: (x -> c x) -> (a, b) -> (c a, c b) --This will error liftTuple :: (forall x. x -> c x) -> (a, b) -> (c a, c b) 我明白,在这种情况下, forall使x成为任何类型( [] , Maybe等)。 我现在正在研究>>=在Monads中的定义: class Applicative m => Monad m where (>>=) :: forall a b. m a -> (a -> m

Monad Transformers lift

I was just looking into monad transformers in real world Haskell. The book said that to make something a monad transformer, you need to make it an instance of the MonadTrans type class. So the book defined a new Transformer, the MaybeT ma transformer. They defined the monadTrans type class for this new transformer: instance MonadTrans MaybeT where lift m = MaybeT (Just `liftM` m) Then th

Monad变形金刚电梯

我只是在真实世界的Haskell中寻找monad变形金刚。 这本书说,为了制造一个monad变压器,你需要把它变成MonadTrans类型的一个实例。 所以本书定义了一台新的变压器,即MaybeT ma变压器。 他们为这个新变换器定义了monadTrans类型类: instance MonadTrans MaybeT where lift m = MaybeT (Just `liftM` m) 然后他们为这个变压器创建了一个MonadState的实例: instance (MonadState s m) => MonadState s (MaybeT m) wh

How to apply a custom Monad Transformer

Say I have some Monadic type data Example a = CheckIt {unwrap :: a} instance Functor Example where fmap f (CheckIt x) = CheckIt (f x) instance Applicative Example where pure = CheckIt CheckIt f <*> CheckIt x = CheckIt (f x) instance Monad (Example) where return = CheckIt e@(CheckIt a) >>= f = f a and I have a function which returns an [a] based on some input: fetchList

如何应用自定义Monad Transformer

假设我有一些Monadic类型 data Example a = CheckIt {unwrap :: a} instance Functor Example where fmap f (CheckIt x) = CheckIt (f x) instance Applicative Example where pure = CheckIt CheckIt f <*> CheckIt x = CheckIt (f x) instance Monad (Example) where return = CheckIt e@(CheckIt a) >>= f = f a 我有一个函数返回一个[a]基于一些输入: fetchList :: b -> [Int] fetchList _ =

Why are monad transformers different to stacking monads?

In many cases, it isn't clear to me what is to be gained by combining two monads with a transformer rather than using two separate monads. Obviously, using two separate monads is a hassle and can involve do notation inside do notation, but are there cases where it just isn't expressive enough? One case seems to be StateT on List: combining monads doesn't get you the right type, and

为什么monad变压器与堆叠monads不同?

在很多情况下,我不清楚将两个单片机与变压器相结合而不是使用两个单独的单片机可以获得什么。 显然,使用两个单独的monad是一件麻烦事,可能会涉及到符号内的符号表示法,但是有些情况下它不够表达? 一个案例似乎是ListT上的StateT:结合monad并没有给你正确的类型,如果你确实通过一堆monad获得了正确的类型,比如Bar(其中Bar a =(Reader r(List(Writer w(Identity a))),它没有做正确的事情。 但是,我希望更一

When a generic type would not be a monad?

Haskell allows to define a new type around another one, thus creating a "type with context". Hence, one may differentiate (Int, Int) in cases such as data Time = Time (Int, Int) --(h:m) and data Coord = Coord (Int, Int) --(x,y). These new types will have related functions knowing that the wrapped "base" type is effectively an Int . One step further, is to create "gene

当一个泛型不会是单子吗?

Haskell允许围绕另一个定义新类型,从而创建一个“带有上下文的类型”。 因此,在例如data Time = Time (Int, Int) - (h:m)和data Coord = Coord (Int, Int) - (x,y)的情况下,可以区分(Int, Int) )。 这些新类型将具有相关功能,因为知道包装的“基本”类型实际上是一个Int 。 更进一步的是,通过在data子句中使用“类型参数”来创建“通用”类型,就像在着名的monad中一样: data Maybe t = Nothing | Just t data Maybe t

Anatomy of a monad transformer

I'm trying to learn monad transformers, based on the standard Haskell libraries (mtl? transformers? not sure which one came with my download of the Haskell platform - 7.4.1). What I believe I've noticed is a common structure for each monad transformer definition: base type ('Base') Monad instance transformer type ('BaseT') Monad instance MonadTrans instance M

Monad变压器的解剖

我试图学习基于标准Haskell库(mtl?变换器?不知道哪一个随我下载了Haskell平台 - 7.4.1)的monad变换器。 我相信我已经注意到每个monad变压器定义的通用结构: 基本类型('基本') Monad实例 变压器类型('BaseT') Monad实例 MonadTrans实例 MonadIO实例 变压器类('MonadBase') 一些操作 其他'BaseT's的实例 举个例子,对于Writer monad来说,会出现: Writer数

What is the name of this Monad Stack function?

I've got a bunch of stateful functions inside a State monad. At one point in the program there needs to be some IO actions so I've wrapped IO inside a StateT getting a pair of types like this: mostfunctions :: State Sometype a toplevel :: StateT Sometype IO a To keep things simple I don't want pass the IO context into the main set of functions and I would like to avoid wrapping the

这个Monad Stack函数的名字是什么?

我在国家monad中有一堆有状态的函数。 在程序中的某个地方需要一些IO操作,所以我在一个StateT中包装了IO,得到了一对类型: mostfunctions :: State Sometype a toplevel :: StateT Sometype IO a 为了简单起见,我不想将IO上下文传递到主函数集中,我想避免将它们封装在monad堆栈类型中。 但为了从顶级函数中调用它们,我需要类似于电梯的东西,但我并不想从内部单子中提取一个值。 相反,我想将StateT monad中的状态转换

Why is ListT monad transformer considered buggy

I've seen mentioned that ListT is a classic example of a buggy monad transformer that doesn't satisfy the monad laws. Can this be demonstrated by a simple example? Edit: My idea with ListT [] is a bit wrong, I missed that the documentation requires the inner monad to be commutative. So, is ListT buggy just in the sense that has this requirement, or is there another problem? (The e

为什么ListT monad变压器被认为是越野车

我已经提到过 ListT是一个不符合单子法的ListT的典型例子。 这可以通过一个简单的例子来证明吗? 编辑:我对ListT []想法有点不对,我错过了文档要求内部monad是可交换的。 那么,仅仅是在有这个要求的意义上,还是存在另一个问题的是ListT越野车呢? (Haskell维基上的例子都使用ListT IO和IO显然是不可交换的。) 一个简单的例子,显示它如何失败的联想法: v :: Int -> ListT [] Int v 0 = ListT [[0, 1]] v 1 =

How do I set up Gtk on Windows for Haskell development?

So far I have installed full version from https://www.haskell.org/platform/windows.html Initially, pacman did not work so I did run as an administrator mingw64.exe found in C:Program FilesHaskell Platform8.2.1msys I have updated the msys2 sytem running pacman -Syu and installed all Gtk libraries. I am trying to compile https://github.com/mmsbrggr/hsudoku using stack. I have gone past the mi

如何在Windows上为Haskell开发设置Gtk?

到目前为止,我已经从https://www.haskell.org/platform/windows.html安装完整版本 最初,pacman没有工作,所以我以管理员mingw64.exe的身份运行 C:Program FilesHaskell Platform8.2.1msys 我更新了运行pacman -Syu的msys2系统并安装了所有的Gtk库。 我正在尝试使用堆栈编译https://github.com/mmsbrggr/hsudoku。 我已经超过了错过的DLL错误,现在我得到以下内容: haskell-gi-base-0.20.4:configure - 使用以下命

How to set cabal extra dirs for all packages in a sandbox

I'm currently working on a Haskell project that uses lots of native code. This means that include files and libraries have to be accessible to cabal. I'm doing that by --extra-lib-dirs and --extra-include-dirs command-line flags. I'm also using cabal sandboxes feature to avoid global dependency hell. The trouble is that cabal often needs to reinstall some of my packages and thus

如何为沙箱中的所有包设置cabal extra dirs

我目前正在研究一个使用大量本机代码的Haskell项目。 这意味着包含文件和库必须可以被cabal访问。 我正在通过--extra-lib-dirs和--extra-include-dirs命令行标志来做到这一点。 我也使用cabal沙箱功能来避免全局依赖地狱。 麻烦的是,cabal经常需要重新安装我的一些软件包,并重新构建它们,这需要本地包含文件和库。 所以我必须在命令行中指定--extra-lib-dirs和--extra-include-dirs,即使对于那些不需要本机代码的程序