1

I'm Trying to expand my understanding about symbols in Haskell :

 $  : Function Application operator (Allow you to apply arguments over a function)
 &  : flipped version of Function Application Operator? (&) = flip ($)
<>  : associative operator (You'll find it in Semigroups and Monoids)
<$> : function application ($) lifted over a Functor structure
<&> : flipped functor map
<*> : applicative operator

Can we make a link between <> and this family <*>,<$>,<&>? I made a quick conclusion when only looking at <*>,<$>,<&> that <..> was related to something over a structure, but then what is the link between structure and associative operator ?

duplode
  • 33,731
  • 7
  • 79
  • 150
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
  • 5
    I think it's best to think of `<>` as being unrelated to other `<...>` operators. (But maybe there's some connection I can't see) – chi Apr 27 '19 at 09:48
  • 2
    I think it's a bit of a tongue-in-cheek reference to the idea that `<...>` itself is some sort of operator on other operators. If you think that `` performs some sort of common lifting operation on an operator `x`, then the generic associative operator "lifts" no particular operator, and so `<...>` "wraps" the null operator to produce `<>`. – chepner Apr 27 '19 at 12:31
  • @chi Applicative is (just like monads famously are) a monoid in the appropriate category. https://arxiv.org/abs/1406.4823 But I very much doubt that this was the justification behind the name decision. – gallais Apr 28 '19 at 11:29

2 Answers2

8

Those names didn't come out of some overarching conceptual scheme. The best way to see that is by tracing their histories:

  • McBride and Paterson's Applicative programming with effects uses an asterisk in a circle, ⊛, as the binary operator of Applicative (note that there are theoretical reasons to pick a *-like symbol that suggests a product). When Control.Applicative made it to base (that is, in base-2.1/GHC 6.6/October 2006), that became <*>, which is, as far as I can see, the closest ASCII approximation to that.

  • The first version of Control.Applicative already featured <$>, and the final version of Applicative programming with effects I linked to above also mentions it (with the minor difference that the <$> there has an Applicative constraint). The point of picking a mashup of $ and <*> as the fmap operator was presumably allowing us to write nice-looking applicative style expressions (f <$> u <*> v <*> w) that could be acceptable substitutes for the idiom brackets mentioned in that paper (which, rendered in ASCII, look like [| f u v w |]).

  • The Monoid class came into being even earlier in the history of base (it already existed as of GHC 5.04.2, in a Control.Monad.Monoid module); however, there wasn't an infix version of mappend in base until version 4.5 (GHC 7.4, early 2012). Applicative programming with effects also mentions monoids, and suggests a circled plus, ⊕, as a binary operator for mappend. As far as I can tell, the <> name was first suggested by Ross Paterson in a Libraries mailing list thread from 2009, and made its way into a preexisting GHC proposal, and presumably also to Edward Kmett's semigroups package, whose Data.Semigroup module was eventually adopted by base. Paterson chose <> for it being a neutral name, which wouldn't suggest any specific monoid (see also: Why is the mappend infix alias <> instead of +?).

duplode
  • 33,731
  • 7
  • 79
  • 150
  • @duplode : about '<*>' you can look at this post : https://stackoverflow.com/questions/55513329/does-in-have-a-special-meaning?noredirect=1#comment97734081_55513329 – Nicolas Henin Apr 27 '19 at 12:47
  • sorry to be more accurate the `*` in `<*>` is deliberate for example so why `<>` would be accidental ? it could have been something else than <> to avoid confusion with the set of `<..>` – Nicolas Henin Apr 27 '19 at 12:58
  • [1/2] @NicolasHenin (1) I meant to link to that other question of yours, but momentarily forgot about it. Now fixed. (2) When it comes to explaining why things are named as they are, I think it is important to look closely at their history. Perhaps Ed Kmett will show up here and correct me by saying he was thinking of `<*>` when he wrote the first version of *semigroups*, but right now I don't see evidence of there being a connection, except by an after-the-fact analogy (which is entirely fine, as long as we recognise it as being after-the-fact). – duplode Apr 27 '19 at 13:24
  • [2/2] @NicolasHenin It is important to be aware that *base*, or Haskell as a whole really, didn't come about in one fell swoop, but rather as the result of a long history of intertwining lines of inquiry and development. – duplode Apr 27 '19 at 13:24
  • @NicolasHenin Digging a little further, I found direct evidence for the origin of the `<>` name -- see my latest edit. Also, I have removed the XMonad `<+>` example, as including it would be anachronistic (its type originally was `ManageHook -> ManageHook -> ManageHook`; it only got generalised to the type of `mappend` with XMonad 0.10 from late 2011). – duplode Apr 27 '19 at 14:21
  • thanks for all the references and the explanations ! – Nicolas Henin Apr 28 '19 at 07:58
1

As far as I can see, <..> has no general meaning. However, there are certainly some connections with other operators, and most of the listed operators have some sort of mnemonic meaning:

  • $ is function application: f $ x = f x. <$> is clearly inspired by $: while f $ x applies f to x, f <$> x applies f to each element inside x. (Personally, <$> is my favourite operator.)
  • The same relation holds between & and <&>.
  • <> is the monoidal append operator: "x" <> "y" <> "z", Sum 1 <> Sum 2 <> Sum 3. (EDIT: The following may or may not be correct - see edit below for more details.) As far as I'm aware those exact characters were just chosen to look nice, although there might be a connection with the use of in mathematics to represent some arbitrary operator.
  • (This was just speculation - see edit below for a more solid account.) I think <*> was chosen to have a nice resonance with <$>: f <$> x <*> y <*> z. Additionally tuples are also known as product types (e.g. OCaml represents tuple types like Int * String, corresponding to Haskell (Int, String)), so there might be a resonance there with applying f $ (x, y, z) (not that anyone would ever do that instead of plain f x y z or f (x, y, z)).

EDIT: Turns out that @chepner knew a bit more about the history than I do - thanks for commenting! In the original paper introducing applicative functors, the operator name was used for the applicative operation; it was ASCII-fied as <*>. The same paper introduced <$>. Also <> may have been inspired by <*> as monoids and applicatives turn out to be related categorically. So amazingly enough, all the angled brackets did turn out to be related to each other! (Albeit very indirectly and tenuously...)

bradrn
  • 8,337
  • 2
  • 22
  • 51
  • 2
    `<*>` is an ASCII representation of the symbol `⊛` used in [the paper that introduced applicative functors](http://www.staff.city.ac.uk/~ross/papers/Applicative.pdf). I'm not sure, but I think the same paper introduced `<$>` as an infix synonym for `fmap`. (It was defined in terms of `pure` and `⊛`, with the proof of its equivalence to `fmap` left unstated.) – chepner Apr 27 '19 at 12:36
  • Wow, I didn't know that @chepner! Can I edit that in? – bradrn Apr 27 '19 at 12:37
  • 1
    There's also the fact that applicative functors are a type of monoidal functor, which could suggest that `<>` is thus a monoid operator without any functorial overtones. – chepner Apr 27 '19 at 12:38
  • @chepner What's a monoidal functor? – bradrn Apr 27 '19 at 12:38
  • Ugh, you had to ask :) Someone with a better grasp of category theory could give a better summary. A monoidal functor is just a functor between monoidal categories, and a monoidal category is a category `C` equipped with (wait for it) an associative bifunctor `foo :: C x C -> C` with an identity object in `C`. – chepner Apr 27 '19 at 12:42
  • Anyway, feel free to add any of this to your answer. – chepner Apr 27 '19 at 12:43
  • 1
    @bradrn : about monoidal functor : https://stackoverflow.com/questions/50702929/monoidal-functor-is-applicative-but-where-is-the-monoid-typeclass-in-the-definit – Nicolas Henin Apr 27 '19 at 12:53