2011-10-12 8 views
167

मैं Learn You a Haskell for Great Good पढ़ रहा हूं, और मुझे कभी नहीं पता कि हास्केल ऑपरेटरों का उच्चारण कैसे करें। क्या उनके पास "वास्तविक" नाम हैं? ?क्या सामान्य हास्केल ऑपरेटरों के लिए उल्लेखनीय नाम हैं?

उदाहरण के लिए, आप इस तरह की अभिव्यक्ति को बड़े पैमाने पर कैसे पढ़ते हैं?

Just (+3) <*> Just 9 

मुझे पता है कि >>= "बाँध", लेकिन क्या दूसरों के बारे में है? चूंकि Google गैर-अल्फान्यूमेरिक वर्णों को ध्यान में नहीं लेता है, इसलिए एक कुशल खोज करना मुश्किल है ...

मुझे एहसास है कि आप अपने स्वयं के ऑपरेटर बना सकते हैं, इसलिए निश्चित रूप से सभी ऑपरेटरों के नाम नहीं हो सकते हैं, लेकिन मैं उम्मीद करते हैं कि आम लोगों (जैसे उन Applicative या Monad में परिभाषित) के नाम होना चाहिए ...

+0

यह एक अच्छा सवाल है, और मुझे किसी भी उत्तर से अवगत नहीं है। शायद हमें एक नामकरण योजना की आवश्यकता है, या शायद लाइब्रेरी लेखकों को हैडॉक दस्तावेज़ों के हिस्से के रूप में उल्लेखनीय नाम प्रदान करना चाहिए। –

+2

बहुत अच्छा सवाल है। आमतौर पर मैंने <*> को "लागू करें" और <$> को "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 मैं इसका उच्चारण करता हूं * लिखें * अगर यह किसी अन्य फ़ंक्शन के लिए तर्क के रूप में प्रकट होता है, उदाहरण के लिए। 'फ़ोल्ड 1 (।) [एफ, जी, एच, आई, जे]' * फ़ोल्डर- एफ, जी, आई, जे। * – fuz

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

ये बहुत स्पष्ट हैं ... मेरा प्रश्न '<*>', '>>' –

+15

पूर्णता के लिए अधिक असामान्य ऑपरेटरों के बारे में था। –

23

मेरा व्यक्तिगत पसंदीदा (<=<) "मछली छोड़ दिया" कर रहे हैं और "सही मछली" (>=>)। जो मोनैड ऑपरेटरों की सिर्फ बाएं और दाएं क्लेस्ली संरचना हैं। फिशी लिखें, लिखें!

+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

आपके उत्तर के लिए धन्यवाद। "डॉलर साइक्लोप" ने मुझे हंसी बना दिया :) –

+6

* साइक्लोप्स * एकवचन है, आपको * एस * ड्रॉप करने की आवश्यकता नहीं है। :) – 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 
संबंधित मुद्दे