Fantasy-land: Link to Hindley-Milner notation explanation

Created on 29 Jan 2017  Â·  7Comments  Â·  Source: fantasyland/fantasy-land

I'm trying to understand some of the method definitions… specifically, what does "~>" mean in the Hindley-Milner notation (is it even Hindley-Milner notation? Got this from Brian Lonsdorf's https://drboolean.gitbooks.io/mostly-adequate-guide/content/ch7.html).

E.g.

concat :: Semigroup a => a ~> a -> a

Here's what I understand:

AFAIK, this notations usually describes functions. The only thing I started out knowing about this notation before doing some research was that it's input1 -> input2 -> ... -> inputN -> output.

In any case, concat is not a function, it's a method - there's an example in the doc: s.concat(b).
So concat is a method on an object of "type" Semigroup (i.e. this object implements Semigroup's interface).
In concat's definition, 'a' is an object which is of type Semigroup because of "Semigroup a =>" part. This is one of the things I didn't know upon first landing on the Fantasy Land doc page and later found out from Brian's book. I landed on the Fantasy Land doc page many times without knowing this (just mentioning in case anyone wants to know some of the issues beginners like myself may have on first encounters with fantasy-land).

Then the definition continues with: "a ~> a -> a"

But concat only actually takes one input, from the e.g. s.concat(b). So a reasonable explanation for "~>" is that it means something like "yes LHS is an argument but via dot notation, not passing it in as an argument" - or something like that.

In any case, could someone please add a link in the README to an explanation of this notation for people who are not familiar with it (or Haskell, or Category theory)?

Many thanks

Most helpful comment

https://sanctuary.js.org/#types provides an explanation, @justin-calleja. We should link to this section or include something similar in the FL readme itself.

All 7 comments

@SimonRichardson how Natural Transformation could help?
I mean in haskell ~> is natural transformation, but we use it here to describe that left side is type of this and right side is arguments, as i understand it has no connection with Natural Transformations. (https://github.com/fantasyland/fantasy-land/pull/147#issue-170054090)

Does it not :embarrassed: oops! I've been using purescript too much recently.

Ignore me - nothing to see here, move along!

If I've forgotten about that, then we should definitely have a bit about it stating the fact!

https://sanctuary.js.org/#types provides an explanation, @justin-calleja. We should link to this section or include something similar in the FL readme itself.

@davidchambers - yep that's exactly what I was looking for. I personally like the more verbose explanation in Sanctuary.js's doc - but I think the issue linked by @safareli ( #147 ), has a nice compact overview of the notation (by @scott-christopher ).

I'll open a PR with your suggestions shortly.

Thanks!

@davidchambers any update on this? Are you waiting for something from my end?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

evilsoft picture evilsoft  Â·  8Comments

ulfryk picture ulfryk  Â·  4Comments

leeoniya picture leeoniya  Â·  6Comments

davidchambers picture davidchambers  Â·  15Comments

ascartabelli picture ascartabelli  Â·  11Comments