常见的 Haskell 运算符是不是有可发音的名称? [关闭]
Posted
技术标签:
【中文标题】常见的 Haskell 运算符是不是有可发音的名称? [关闭]【英文标题】:Are there pronounceable names for common Haskell operators? [closed]常见的 Haskell 运算符是否有可发音的名称? [关闭] 【发布时间】:2011-12-06 12:12:47 【问题描述】:我正在阅读Learn You a Haskell for Great Good,但我从来不知道如何发音 Haskell 运算符。他们有“真实”的名字吗? ?
例如,你如何大声朗读这样的表达方式?
Just (+3) <*> Just 9
我知道>>=
是“绑定”,但是其他的呢?由于 Google 不考虑非字母数字字符,因此很难进行有效的搜索...
我意识到您可以创建自己的运算符,所以当然不是所有运算符都可以有名称,但我希望常见的运算符(例如在 Applicative
或 Monad
中定义的运算符)必须有名称......
【问题讨论】:
非常好的问题。通常我将 读为“apply”,将 读为“fmap”。至于其他我不知道。 这是"Haskell: How is<*>
pronounced?" 的副本吗?即使不是,它的答案也可能值得一试。
我会发布一个答案,但我觉得可能会有更好的答案,就像 Antal 建议的那样。编辑:看到?更好的答案:D
另外,请查看the Haskell wiki's page on pronunciation。它不完整,但相关。
()
发音为单位。有一次,我发现自己被困在数百名函数式程序员的观众面前,不知道在我的幻灯片上如何发音。
【参考方案1】:
我冒昧地将答案组装成一个非常简单的 haskell 程序,它只能通过模式匹配尝试将 haskell 代码翻译成英文。我称它为letterator
,因为它将符号转换为字母
-- letterator
main = translateLn <$> getLine >>= putStrLn
translateLn :: String -> String
translateLn = unwords . map t . words
t :: String -> String -- t(ranslate)
-- historical accurate naming
t "=" = "is equal too" -- The Whetstone of Witte - Robert Recorde (1557)
-- proposed namings
-- src http://***.com/a/7747115/1091457
t ">>=" = "bind"
t "*>" = "then"
t "->" = "to" -- a -> b: a to b
t "<$" = "map-replace by" -- 0 <$ f: "f map-replace by 0"
t "<*>" = "ap(ply)" -- (as it is the same as Control.Monad.ap)
t "!!" = "index"
t "!" = "index/strict" -- a ! b: "a index b", foo !x: foo strict x
t "<|>" = "or/alternative" -- expr <|> term: "expr or term"
t "[]" = "empty list"
t ":" = "cons"
t "\\" = "lambda"
t "@" = "as" -- go ll@(l:ls): go ll as l cons ls
t "~" = "lazy" -- go ~(a,b): go lazy pair a, b
-- t ">>" = "then"
-- t "<-" = "bind" -- (as it desugars to >>=)
-- t "<$>" = "(f)map"
-- t "$" = "" -- (none, just as " " [whitespace])
-- t "." = "pipe to" -- a . b: "b pipe-to a"
-- t "++" = "concat/plus/append"
-- t "::" = "ofType/as" -- f x :: Int: f x of type Int
-- additional names
-- src http://***.com/a/16801782/1091457
t "|" = "such that"
t "<-" = "is drawn from"
t "::" = "is of type"
t "_" = "whatever"
t "++" = "append"
t "=>" = "implies"
t "." = "compose"
t "<=<" = "left fish"
-- t "=" = "is defined as"
-- t "<$>" = "(f)map"
-- src http://***.com/a/7747149/1091457
t "$" = "of"
-- src http://***.com/questions/28471898/colloquial-terms-for-haskell-operators-e-g?noredirect=1&lq=1#comment45268311_28471898
t ">>" = "sequence"
-- t "<$>" = "infix fmap"
-- t ">>=" = "bind"
--------------
-- Examples --
--------------
-- "(:) <$> Just 3 <*> Just [4]"
-- meaning "Cons applied to just three applied to just list with one element four"
t "(:)" = "Cons"
t "Just" = "just"
t "<$>" = "applied to"
t "3" = "three" -- this is might go a bit too far
t "[4]" = "list with one element four" -- this one too, let's just see where this gets us
-- additional expressions to translate from
-- src http://***.com/a/21322952/1091457
-- delete (0, 0) $ (,) <$> [-1..1] <*> [-1..1]
-- (,) <$> [-1..1] <*> [-1..1] & delete (0, 0)
-- liftA2 (,) [-1..1] [-1..1] & delete (0, 0)
t "(,)" = "tuple constructor"
t "&" = "then" -- flipped `$`
-- everything not matched until this point stays at it is
t x = x
【讨论】:
【参考方案2】:+ plus
- minus (OR negative OR negate for unary use)
* multiply OR times
/ divide
. dot OR compose
$ apply OR of
【讨论】:
这些很明显...我的问题是关于更不寻常的运算符,例如<*>
、>>
...
为了完整性。【参考方案3】:
我是这样发音的:
>>= 绑定 >> 那么 *> 那么 -> 到 a -> b: a 到 b (因为它脱糖为 >>=) (f) 映射 0 ap(ply) (因为它与 Control.Monad.ap 相同) $ (无,就像 " " [空格]) .管道到 a 。 b: "b 管道到 a" !!指数 !索引 / 严格 a ! b: "a 索引 b", foo !x: foo strict x 或 / 替代 expr term: "expr or term" ++ 连接/加/追加 [] 空列表 : 缺点 :: 类型 / 为 f x :: Int: f x 类型 Int \ 拉姆达 @ as go ll@(l:ls): go ll as l cons ls ~lazy go ~(a,b): go lazy pair a, b【讨论】:
对我来说,(.)
是“撰写”。
@luqui 如果它作为另一个函数的参数出现,我将其发音为 compose,例如。 foldr1 (.) [f,g,h,i,j]
foldr-one 组合 f、g、i、j 的列表。
我通常将(.)
发音为of
,将($)
发音为applied to
:f . g . h $ x
因此读作f of g of h applied to x
。但我理解这种观点的分歧!
我认为将(.)
发音为“之后”更明智。组合可以在两个方向上表示,并且将其称为“之后”也可以立即解释它是如何工作的。
我会调用 ++
"append" 而不是 concat
,因为 concat
在 Haskell 中已经是一个东西,而且它的实用性非常不同。【参考方案4】:
| sym | pronunciation |
|------|--------------------------------------------------|
| | | "such that" |
| <- | "is drawn from" |
| = | "is defined to be" / "is defined as" |
| :: | "has type" / "of type" / "is of type" |
| -> | "a function that takes ... and returns a ..." / |
| | "function that maps" / |
| | "is a function from" / |
| | "to" |
| $ | "apply" |
| _ | "whatever" |
| !! | "index" |
| ++ | "concat" |
| [] | "empty list" |
| : | "cons" |
| \ | "lambda" |
| => | "implies" / "then" |
| *> | "then" |
| <$> | "fmap" / "dollar cyclops" |
| <$ | "map-replace by" |
| <*> | "ap" / "star cyclops" |
| . | "pipe to" / "compose" / "dot" |
| <|> | "or" |
| @ | "as" |
| ~ | "lazy" |
| <=< | "left fish" |
【讨论】:
【参考方案5】:我个人最喜欢的是“左鱼”(<=<) 和“右鱼”(>=>)。这只是单子运算符的左右 Kleisli 组成。作曲,作曲!
【讨论】:
以上是关于常见的 Haskell 运算符是不是有可发音的名称? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
Scala 是不是有类似于 Haskell 的 `$` 的运算符?