- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图理解下面的表达。它转换字符列表['a','b','c']
到字符串列表 ["a", "b", "c"]
liftM (:[]) "abc"
最佳答案
机器猴头运算符(operator)(:[])
只是 section缺点列表(:)
和空列表[]
,即 (:[])
相当于(\x -> x:[])
;反过来也可以使用列表语法编写为 (\x -> [x])
.
这样重写,我们有
liftM (\x -> [x]) "abc"
"abc"
也只是
character list ['a', 'b', 'c']
的语法糖,所以我们可以反过来将上面的内容重写为
liftM (\x -> [x]) ['a', 'b', 'c']
liftM
is just fmap
from the Dark Days when Functor
wasn't a superclass of Monad
, 给
fmap (\x -> [x]) ['a', 'b', 'c']
Functor
[]
的实例套
fmap = map
, 给
map (\x -> [x]) ['a', 'b', 'c']
[['a'], ['b'], ['c']]
["a", "b", "c"]
关于haskell - LiftM (:[]) work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31763252/
在 Haskell 中,(liftM .liftM)、(liftM .liftM .liftM) 等有别名吗? 这样我就不必那么冗长了,例如: (liftM . liftM) (+ 1) [Just
我试图理解下面的表达。它转换字符列表['a','b','c']到字符串列表 ["a", "b", "c"] liftM (:[]) "abc" 这是怎么发生的? 最佳答案 机器猴头运算符(operat
最近我一直在编写在 IO monad 中返回数据结构的 FFI 代码。例如: peek p = Vec3 (#peek aiVector3D, x) p (#peek
replicate 3 "hi" 产生 ["hi", "hi", "hi"] 但是 liftM (replicate 3) "hi" 产生 ["hhh", "iii"] liftM 是如何(精确地)运
monad 和 applicative 的区别在于前者可以根据之前的结果选择下一个计算: (\x -> if x == 1 then (\_ -> []) else (\y -> (\z -> \w
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 2年前关闭。 Improve th
在 Haskell 中使用一元表达式时,使用 liftM的(即使在中缀位置)对我来说通常显得很不美观且冗长。 大多数其他一元基元( >>= 、 >> )甚至 liftM的纯吊坠 $是中缀运算符。这让我
我有以下功能: sendq :: Socket -> B.ByteString -> String -> IO PortNumber -> IO () sendq s datastring host
我对 liftM 如何保留上下文感到困惑,特别是在 Writer monad 的情况下。我一直在阅读“Learn You a Haskell for Great Good”,并且一直停留在它对 lif
根据the Typeclassopedia (以及其他来源),Applicative逻辑上属于 Monad和 Pointed (因此 Functor )在类型类层次结构中,所以如果 Haskell 前
这个问题已经有答案了: What is the monomorphism restriction? (1 个回答) 已关闭 6 年前。 当我在 ghci 中定义此类函数时: > :m Control.
我有 getLinesIn = liftM lines 。 getContents 比 readAndWriteIn = do list m0 String 与实际类型 IO String 匹配
(注意:我使用 Haskell 术语来表达问题;欢迎使用相同的术语和/或范畴论的数学语言来回答,包括我谈到仿函数和单子(monad)定律时的正确数学定义和公理。) 众所周知,每个 monad 也是一个
在 Haskell 中,以下工作: > (+) `liftM` (Just 3) `ap` (Just 5) Just 8 Frege 提示使用括号: frege> (+) `liftM` (Just
如果我有一个采用两个类型参数的 monad 转换器类型,我可以使用 liftM将值提升到转换后的 monad 中: scala> val o = 1.point[List].liftM[OptionT
两个表达式 y >> pure x liftM (const x) y 在 Haskell 中具有相同的类型签名。我很好奇它们是否等价,但我既无法提供事实证明,也无法提供反例。 如果我们重写这两个表达
我是一名优秀的程序员,十分优秀!