monads

Failed to declare MonadPlus interface constrained on Monad

落花浮王杯 提交于 2021-01-04 07:44:27
问题 I'm trying to declare MonadPlus interface like that: module NanoParsec.Plus %access public export interface Monad m => MonadPlus m where zero : m a plus : m a -> m a -> m a But have an error: | 5 | interface Monad m => MonadPlus m where | ~~~~~~~ When checking type of constructor of NanoParsec.Plus.MonadPlus#Monad m: When checking argument m to type constructor Prelude.Monad.Monad: Type mismatch between Type (Type of m) and Type -> Type (Expected type) What I'm doing wrong? How to fix this?

What is the type of return 5 in Haskell when no context is given?

两盒软妹~` 提交于 2021-01-02 05:18:39
问题 In this question the OP asks what the type of the expression return 5 is and the answer has already been given in that question: it is a generic type, as can be verified by typing :t return 5 in the Haskell interpreter: return 5 :: (Num a, Monad m) => m a The specific implementation of return is determined by the context in which it appears: type inference will restrict m to a specific monad such as Maybe , [] , IO , and so on. I can also force the interpreter to pick a specific monad by

What is the type of return 5 in Haskell when no context is given?

青春壹個敷衍的年華 提交于 2021-01-02 05:18:10
问题 In this question the OP asks what the type of the expression return 5 is and the answer has already been given in that question: it is a generic type, as can be verified by typing :t return 5 in the Haskell interpreter: return 5 :: (Num a, Monad m) => m a The specific implementation of return is determined by the context in which it appears: type inference will restrict m to a specific monad such as Maybe , [] , IO , and so on. I can also force the interpreter to pick a specific monad by

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

岁酱吖の 提交于 2020-12-29 05:54:43
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

拜拜、爱过 提交于 2020-12-29 05:53:47
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

帅比萌擦擦* 提交于 2020-12-29 05:53:28
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is it possible to create a Monad that count the number of instructions?

妖精的绣舞 提交于 2020-12-26 05:55:47
问题 Thinking about monad, it came to me the idea of a monad as the way to break with the Von Neumann architecture. The Von Neumann architecture uses a set of instructions (called program) to change the data in memory and the execution of each instruction of the program updates a program counter to know whom instruction is the next to execute. If we think about the Von Neumann architecture as a monad, the bind operator (>>=) update the program counter. We can make a Monad that break Von Neumann

How does mapM work with const functions in Haskell?

怎甘沉沦 提交于 2020-12-08 07:52:48
问题 as I had been looking for ways to optimize a password cracker I had been making, I came across a much shorter implementation of all possible character combinations in a list, which used this function: mapM (const xs) [1..n] where xs could be the characters available, and n the length of the desired words. so mapM (const "abcd") [1..4] would output a list ["aaaa","aaab","aaac","aaad","aaba","aabb"..] and so on. Only the length matters for the list of th right, I could have written ['f','h','s'