2011-10-12 3 views
167

私はLearn You a Haskell for Great Goodを読んでおり、Haskell演算子の発音方法はわかりません。彼らは「本当の」名前を持っていますか? ?一般的なHaskell演算子の発音可能な名前はありますか?

たとえば、このような表現をどのように大声で読みますか?

Just (+3) <*> Just 9 

私は>>=は、「バインド」ですが、どのような他の人について、ことを知っていますか? Googleでは英数字以外の文字を考慮しないため、効率的な検索を行うのは難しいです...

私はあなた自身の演算子を作成することができるので、すべての演算子が名前を持つことはできませんが、ここで

+0

これは良い質問ですが、私は何の答えも知らないのです。おそらく、名前付けスキームが必要かもしれません。あるいは、ライブラリ作成者がHaddockのドキュメントの一部として発音可能な名前を提供する必要があります。 –

+2

非常に良い質問です。通常、私は<*>を "apply"、<$>を "fmap"と読みます。他の人は私には分かりません。 – DuoSRX

+3

これは["Haskell:どのように' <*> 'が発音されたのですか?"](http://stackoverflow.com/questions/3242361/haskell-how-is-pronounced)?たとえそうでないとしても、その答えはおそらくチェックアウトする価値があります。 –

答えて

154

が、私はそれらを発音方法です...名前を持っている必要があります(ApplicativeまたはMonadで定義されたものなど)一般的なものと期待:

 
>>=  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別の関数の引数として表示される場合は、* compose *と発音します。 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

[1匹の魚、2匹の魚、赤い魚、青い魚!](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

*サイクロプスは単数ですので、* 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 
関連する問題