Hacker News new | ask | show | jobs
by innguest 4089 days ago
I'm not forcing any definition here.

Just 5 is a map, and Nothing is a map. Let's watch:

Just 5 >> Nothing

Just is a map that accepts an input and returns that input decorated with a certain structure.

  Just ---(5)---> (Just 5)
Which means there's an arrow that shoots out of (Just), itself a map - because it has arrows coming in and going out - which we can use to arrive at (Just 5).

Then (>>) combines the Just 5 map - a map that takes a function, like (>>) in this case, and returns another function that accepts another Maybe and returns another Maybe.

Let's draw that:

  (Just 5) ---(>>)---> (\x -> (Just 5) >> x)
Which means there's an arrow that shoots out of (Just 5), itself a map, to which in this example we go to its index (>>) and retrieve the resulting value, another map: (\x -> (Just 5) >> x)

Now we give the map above, the input Nothing, and it returns the value Nothing, itself a map, because it has arrows coming in and shooting out as can be seen below:

  (\x -> (Just 5) >> x) ---(Nothing)---.====(>>)====>> (\x -> Nothing >> x)
                              ^        |
                              |________|
The ====> arrow above I've added to show other possible arrows you might want to take from Nothing onwards.

In other words, to say that a value in Haskell is not a map is to say it can't be arrived at, nor escaped from. If I understand correctly, the only value that can't be escaped from is Bottom, which has 0 arrows pointing out of it. Therefore it is not a map. But Just, Just 5 and Nothing are all maps, as they all have arrows pointing to them (which means we can arrive at them) and arrows pointing out of them (which means we can escape from them). Something that has arrows coming in and going out, we call a morphism.

1 comments

This seems deeply confusing, and possibly deeply confused. Something that has arrows coming in and going out we call an object. We call the arrows morphisms. Every "a" in (+) :: Num a => a -> a -> a has an arrow going in and/or coming out. It seems unhelpful to say "plus composes functions".
I agree I'm a bit confused there, namely in that the maps are not contained in the objects, but as you said, are in the arrows themselves.

So (>>) contains a map that in its Nothing index has the lambda (\x -> Nothing >> x). You're right.

And yes, it is unhelpful to say plus composes functions. However, that is indeed what it does in the abstract world that Haskell pretends to be modelling - numbers (Church numerals) are functions and the arithmetic operators combine those functions. So, while unhelpful, it is not wrong, and saying it isn't so will confuse beginners that have done those "numbers from lambdas" exercises.