常见的Haskell运算符有明显的名称吗?[关闭]


204

我正在阅读Learn Has a Haskell for Great Good,但我不知道该如何发音Haskell运算符。他们有“真实”名称吗??

例如,如何朗读这样的表达式?

Just (+3) <*> Just 9

我知道那>>=是“绑定”,但是其他人呢?由于Google不考虑非字母数字字符,因此很难进行有效的搜索...

我意识到您可以创建自己的运算符,因此当然并非所有运算符都可以具有名称,但是我希望常见的运算符(例如,在Applicative或中定义的运算符Monad)必须具有名称...


这是一个很好的问题,我不知道有任何答案。也许我们需要一个命名方案,或者库作者应该在Haddock文档中提供可发音的名称。
保罗·约翰逊

3
很好的问题。通常我将<*>读为“ apply”,将<$>读为“ fmap”。至于其他我不知道。
DuoSRX 2011年

3
这是“ Haskell:如何<*>发音”的副本吗??即使不是,它的答案也可能值得一试。
Antal Spector-Zabusky 2011年

8
另外,请查看Haskell Wiki上有关发音的页面。它是不完整的,但相关。
Antal Spector-Zabusky 2011年

3
()是发音单位。有一次,我发现自己陷入了数百名函数式程序员的听众面前,他们不知道如何在幻灯片上发音。
sigfpe 2014年

Answers:


194

这是我的发音:

>> =绑定
>>然后
*>然后
->到                 a- > b:a到b 
<-绑定               (因为它对>> =无效)
<$>(f)地图
<$ map-replace by     0 <$ f:“ f map-replace by 0” 
<*> ap(ply)            (与Control.Monad.ap相同) 
$                          (无,与“” [空白] ) 
。管道连接到            。b:“ b管道到a”
!! 指数
!索引/严格     一个!b:“ a索引b”,foo!x:foo严格x 
<|>或/ Alternative   expr <|> term:“ expr或term”
++ concat /加号/附加
[]空清单
:缺点
::类型/作为       fx :: Int:类型Int的fx
\ lambda
@如                 去LL @(升:LS):转到LL作为升缺点LS 
〜懒               去〜(A,B):去懒惰对A,B

100
对我来说,(.)是“组成”。
luqui 2011年

47
我通常相当发音(.)of($)applied tof . g . h $ x因此被读取f of g of h applied to x。但是我理解这种观点的分歧!
2011年

39
我认为(.)将“ after” 发音为更明智。可以从两个方向表示合成,将其称为“之后”也可以立即说明其工作原理。

1
@Tinctorius,构图是在之后还是之前取决于一个不普遍的观点。例如,在中const 42 . fix id,我们真的可以说const 42无限循环“之后”吗?
luqui 2011年

7
我将其称为++“ append”而不是concat,因为concat在Haskell中已经是一回事了,它的效用是非常不同的。
本杰明·科瓦奇

42
| 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"                                      |

2
感谢您的回答。“美元独眼巨人”让我笑了:)
托马斯·

9
独眼巨人是单数,不需要删除s。:)

1
<*呢 它很少使用而没有通用名称吗?
Dannyu NDos


8

我自由地将答案组合到一个非常简单的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://stackoverflow.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://stackoverflow.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://stackoverflow.com/a/7747149/1091457
t "$"   = "of" 

-- src http://stackoverflow.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://stackoverflow.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

4
+      plus
-      minus (OR negative OR negate for unary use)
*      multiply OR times
/      divide
.      dot OR compose
$      apply OR of

12
这些的人是相当明显的...我的问题是关于更不寻常的运营商像<*>>>...
托马斯Levesque的

20
为了完整性。
Thomas Eding
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.