2011-10-12 45 views
167

我在閱讀Learn You a Haskell for Great Good,我從不知道如何發音Haskell運營商。他們有「真實」的名字嗎? ?是否有常見的Haskell運算符的發音名稱?

例如,你如何朗讀這樣的表達式?

Just (+3) <*> Just 9 

我知道>>=是「綁定」,但其他的呢?由於谷歌不考慮非字母數字字符,這是很難做一個有效的搜索...

我知道你可以創建自己的運營商,所以當然不是所有的運營商都可以有名字,但我預計,常見的(在ApplicativeMonad例如那些定義)的名稱必須...

+0

它是一個很好的問題,我不知道任何答案。也許我們需要一個命名方案,或者圖書館作者應該提供可發音的名字作爲Haddock文檔的一部分。 –

+2

非常好的問題。通常我讀<*>爲「apply」,<$>爲「fmap」。至於其他人,我不知道。 – DuoSRX

+3

這是一個重複的[「哈斯克爾:'<*>'怎麼發音?」](http://stackoverflow.com/questions/3242361/haskell-how-is-pronounced)?即使不是,它的答案也許值得一試。 –

回答

154

這是我如何發音他們:

 
>>=  bind 
>>  then 
*>  then 
->  to    a -> b: a to b 
<-  bind    (as it desugars to >>=) 
<$>  (f)map 
<$  map-replace by 0 <$ f: "f map-replace by 0" 
<*>  ap(ply)   (as it is the same as Control.Monad.ap) 
$       (none, just as " " [whitespace]) 
.  pipe to   a . b: "b pipe-to a" 
!!  index 
!  index/strict a ! b: "a index b", foo !x: foo strict x 
<|>  or/alternative expr <|> term: "expr or term" 
++  concat/plus/append 
[]  empty list 
:  cons 
::  of type/as  f x :: Int: f x of type Int 
\  lambda 
@  as    go [email protected](l:ls): go ll as l cons ls 
~  lazy    go ~(a,b): go lazy pair a, b 
+0

謝謝,這正是我期待的答案! –

+87

給我,'(。)'是「撰寫」。 – luqui

+0

@luqui我發音*撰寫*如果它顯示爲另一個函數的參數,例如。 'foldr1(。)[f,g,h,i,j]'* foldr-one構成f,g,i,j的列表。* – fuz

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

這些是非常明顯的......我的問題是關於'<*>'',''''...... –

+15

更不尋常的運營商爲了完整性。 –

23

我個人最喜歡的是「左魚」 (<=<)和「正確的魚」(>=>)。這只是Kleisli左側和右側單子經營者的組成。撰寫腥,撰寫!

+0

[一條魚,兩條魚,紅色的魚,藍色的魚!](https://en.wikipedia.org/wiki/One_Fish,_Two_Fish,_Red_Fish,_Blue_Fish) – 4castle

29
| 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

感謝您的回答。 「美元cyclop」讓我大笑:) –

+6

*獨眼巨人*是單數,你不需要放棄* s *。 :) – Rahul

4

我冒昧的答案組裝成只有通過模式匹配試圖Haskell代碼翻譯成英文一個非常簡單的Haskell程序。

-- literator 

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 [email protected](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