刚刚被介绍给哈斯克尔的单子,并与>>碰到了一些障碍。 >>=对我来说很有意义,因为我可以得到下面的出前奏曲: Prelude> Just 1 >>= (\ x -> Just (x+1))
Just 2
我的理解是,>>是一样的绑定,但仅用于当函数是关于恒定的参数。但是,当我尝试这样做,在前奏: Prelude> Just 1 >> (\_ -> Just 10)
<interactiv
我在阅读Purescript通过示例并介绍了读者单元的部分。示例如下: createUser :: Reader Permissions (Maybe User)
createUser = do
permissions <- ask
if hasPermission "admin" permissions
then map Just newUser
els
使用作家单子#尾递归 let inline bind ma fm =
let (Writer (a, log1)) = ma
let mb = fm a
let (Writer (b, log2)) = mb
let sum = (^w : (static member add : ^w * ^w -> ^w) (log1, log2))
Writ
我知道我可以使用函数单子来实现类似下面的一个结构(在这里我重复使用多次调用的参数不明确引用它)之前执行转换到输入: compute_v0 :: String -> String
compute_v0 = do
x <- length -- (using the argument implicitly here)
top <- head -- (and here)
r
我遇到cats/monads /理解问题。 请考虑下面的代码片段: import cats._
import cats.implicits._
final case class My[T]()
implicit val monadMy: Monad[My] = new Monad[My] { ... }
// this compiles
def test11[A, B](m: My[