Je lis Learn You a Haskell for Great Good , et je ne sais jamais prononcer les opérateurs Haskell. Ont-ils de "vrais" noms? ?
Par exemple, comment lisez-vous à haute voix une expression comme celle-ci?
Just (+3) <*> Just 9
Je le sais >>=
est "lier", mais qu'en est-il des autres? Étant donné que Google ne prend pas en compte les caractères non alphanumériques, il est difficile de faire une recherche efficace ...
Je me rends compte que vous pouvez créer vos propres opérateurs, donc bien sûr tous les opérateurs ne peuvent pas avoir de noms, mais je m'attends à ce que les opérateurs communs (par exemple ceux définis dans Applicative
ou Monad
) doivent avoir des noms .. .
Voici comment je les prononce:
>> = lier >> puis *> puis -> à a -> b: a à b <- lier (comme il évoque à >> =) <$> (f) carte <$ carte-remplacer par 0 <$ f: "f map-replace by 0" <*> ap (pli) (car c'est la même chose que Control.Monad.ap) $ (aucun, tout comme "" [espaces blancs]) . tuyau à une . b: "b pipe-to a" !! indice ! index/strict une ! b: "un index b", foo! x: foo strict x <|> ou/alternative expr <|> terme: "expr ou terme" ++ concat/plus/append [] liste vide : contre :: de type/as f x :: Int: f x de type Int \lambda @ as go ll @ (l: ls): go ll as l cons ls ~ paresseux aller ~ (a, b): aller paresseux paire a, b
| 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" |
J'ai pris la liberté d'assembler les réponses dans un programme haskell très simple, que seule la correspondance de motifs essaie de traduire le code haskell en anglais. Je l'appelle letterator
car il traduit les symboles en lettres
-- 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
+ plus
- minus (OR negative OR negate for unary use)
* multiply OR times
/ divide
. dot OR compose
$ apply OR of