@MartinEscardo@mathstodon.xyz
@MartinEscardo@mathstodon.xyz avatar

MartinEscardo

@MartinEscardo@mathstodon.xyz

Professor at the University of Birmingham, UK.
I am interested in constructive mathematics and (constructive and non-constructive) homotopy type theory and univalent foundations, connections of topology with computation, (infinity) topos theory, locale theory, domain theory, combinatorial game theory and much more.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

johncarlosbaez, (edited ) to random
@johncarlosbaez@mathstodon.xyz avatar

Here in Scotland a lot of things are "bonnie" or "wee". For example there are restaurants in Edinburgh called The Bonnie Burrito and the Wee Greek Kitchen. This must take its mental toll: at a Christmas concert tonight, the choir director slipped and announced that next we were going to hear "Three Wee Kings of Orient Are".

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@johncarlosbaez

"Wee" is indeed the most distinguishing characteristic of the language in Scotland.

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

Can newspapers please stop saying "formely known as Twitter".

This is so annoying. Everybody knows by know what X is.

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

What people call "engineering problems" in programming languages and proof assistants are actually subtle (meta)mathematical problems.

And they haven't been solved so far. My favourite example is type classes. They solve an important unspecified problem, and they don't solve it well enough.

kosmikus, to haskell
@kosmikus@functional.cafe avatar

Just ~90 minutes until the start of episode 16 of The Unfolder. This time about some Haskell history (the Applicative Monad Proposal), a recent Mastodon thread by @MartinEscardo , and about DerivingVia!

https://www.youtube.com/watch?v=tnCHrPZk8xo&list=PLD8gywOEY4HaG5VSrKVnHxCptlJv2GAn7&index=16

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@kosmikus

Nice!

You explained how to make the new world to accommodate the old world.

But what if back in 2015 people wanted to use Classical Monads with Functor and Applicative, without changing the ghc library for monads/applicative/functor?

Could this new technology you discussed today be used for that, if it were available at that time? So that we could still have the classical definition of monad today and at the same time please people who wanted to make the change?

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@kosmikus

Can I ask you for one more thing?

I provided, in my original thread, a proposal (to myself) of how to teach monads next time.

Then you improved this in your talk.

Would you be willing to post a concise counter-proposal in that thread, based on your talk, in the style of my proposal? (And then link to the talk for a full explanation.)

I think it would be nice to have this explicitly recorded for future reference.

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

{- I think I am going to teach Haskell monads like this next year. -}

{-# Language UndecidableInstances #-}

{- Original definition of Haskell monad. -}

class Monad' m where
return' :: a -> m a
bind' :: m a -> (a -> m b) -> m b

{- Nonsense new definition. -}

{-
class Functor f where
fmap :: (a -> b) -> f a -> f b

class Functor f => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b

class Applicative m => Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b

return = pure
-}

{- We get a Monad from a Monad'. -}

instance Monad' m => Monad m where
(>>=) = bind'

{- This is because we can always define Functor and Applicative as follows. -}

instance Monad' m => Functor m where
fmap f xm = do
x <- xm
pure (f x)

instance Monad' m => Applicative m where
pure = return'
fm <*> xm = do
f <- fm
x <- xm
pure (f x)

{- Example. An economic definition of the Maybe monad. -}

data Maybe' a = Nothing' | Just' a

instance Monad' Maybe' where
return' = Just'
bind' Nothing' f = Nothing'
bind' (Just' x) f = f x

{- To test this, define a function using Monad rather than Monad'. -}

fibm :: Monad m => Integer -> m Integer
fibm 0 = pure 0
fibm 1 = pure 1
fibm n = do
x <- fibm (n-2)
y <- fibm (n-1)
pure (x+y)

{- We can use it with the Maybe' Monad automatically derived from the Maybe' Monad'. -}

fib11 :: Maybe' Integer
fib11 = fibm 11

1/

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

It was already difficult to teach monads to 2nd year functional programming students, and the new definition seems to be designed to make them deliberately incomprehensible.
2/

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

The whole point of monads presented as Kleisli triples, which is what Monad' amounts to, is to avoid having to define and prove functoriality and naturality.

The new Haskell definition misses this point.

Moreover, "Applicative" is a distraction.

It is used sometimes, but only very occasionally, and, more importantly, it is hardly at the core of the definition of monad.

In fact, here we have it only because our monads (in either form) are internally defined and hence automatically strong as we are working in something that looks more or less like a cartesian closed category (but it really isn't a cartesian closed category, as the universal property of exponentials for function types doesn't really hold (meaning that it fails).)

3/

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

So there are two big mistakes in the new definition.

(1) It has got the mathematics wrong.

(2) It makes it incredibly hard to teach to programmers.

What a pity, because it is a really useful mathematical abstraction with useful uses in programming.

4/

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

Epilogue.

The people who advocate the new Monad as opposed to the original Monad' should be sentenced to teach Monads for ever to undergrad students in their after-life.

And should avoid claiming that Haskell is informed by mathematics and tries to make it easier to reason about programs.

🙂

Good night.

5/5

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

Let me elaborate a bit further.

While it is true that Functor and Applicative are useful type classes in Haskell, it is also the case that for Haskell Monads we don't really have a choice for what its functorial and applicative parts are, if we are to obey the functorial, applicative and monad laws.

Moreover for monads (in Kleisli form as in Haskell) we don't need to understand Functor and `Applicative first in order to understand the original Haskell definition

class Monad m where
return :: a -> m a
(>>=) :: m a -> (a -> m b) -> m b

Forcing to define Functor as a pre-requisite to define Monad is OK-ish, but still inelegant from both mathematical and computational points of view, because we don't really have a choice, up to (observational program) equivalence.

But forcing to define Applicative as a prerequisite for Monad goes too far in terms of cognitive overload.

Like functoriality, the applicativity of a Haskell monad is uniquely determined for all monads. Hence having to define it every time for every monad is a disservice to (mathematical and computational) simplicity and a source of boilerplate.

In particular, how do you explain to students that (1) yes, they have to define Functor and Applicative, but (2) no, they don't really have a choice, other than maybe writing more efficient code, but in any case there is default code that is required to be equivalent to their more efficient code.

In light of (1) and (2), I don't consider reasonable to define Monad in Haskell in the current way.

6/5

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

Of course, there is an alternative way to support the current Haskell definition of Monad.

We can teach 2nd-year computer-science undergrad students category theory first, and in particular cartesian closed categories, and then explain monads, internally defined monads, monads in Kleisli form, and then show that internally-defined monads in Kleisli form are automatically functorial and applicative (as well as natural).

And then, digression, we can discuss categorical models of Haskell, and point out that, actually, none of them can possibly be cartesian closed, because currying-uncurrying doesn't really satisfy the required property for cartesian closed categories, namely that they are inverses of each other in Haskell, because they are not in Haskell (they are in Miranda).

7/5

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

Further, monads in Haskell are automatically, strong. But luckily nobody so far has had the brilliant idea of creating a type class StrongFunctor as an additional prerequite to define Haskell monads. (I hope this post is not considered as an invitation, but, if it is, you may further consider monoidal monad as an intermediate step, as the strength is a particular case of the (automatic) monoidality of Haskell monads.)

As you can see, we are going in the direction of applied nonsense, where the so-called abstract nonsense teaches that none of this is necessary as we have it for free.

8/5

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

I promise to stop. But don't take my word for it.

The summary is that the current definition of Haskell monad adds consequences of the original definition as part of the new definition.

Consider this question seriously: why do that?

9/5

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

Tomorrow at 19:30 GMT, "The Haskell Unfolder" will have an episode "monads and deriving via" live at YouTube.

Abstract. In this episode, we'll see how deriving-via can be used to capture rules that relate type classes to each other. As a specific example, we will discuss the definition of the Monad type class: ever since this definition was changed back in 2015 in the Applicative Monad Proposal, instantiating Monad to a new datatype requires quite a bit of boilerplate code. By making the relation between "classic monads" and "new monads" explicit and using deriving-via, we can eliminate the boilerplate.

https://www.youtube.com/watch?v=tnCHrPZk8xo&list=PLD8gywOEY4HaG5VSrKVnHxCptlJv2GAn7&index=16

@kosmikus

10/5

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

In the last three weeks, I learned in practice something I knew in theory but didn't pay attention to before.

Batteries don't work well when they are too cold.

My ebike journeys to/from work started to use 30% of the battery, rather the usual 10-20%.

At first I thought it was just getting old. But really it is just the fact that tomorrow is winter officially in this side of the world.

Just removing the battery from the bike and taking it to my office to have it warm for my journey back made it work as usual.

Additionally, now I wait for the battery to get to room temperature before charging it at home.

The downside is that this requires a lot of baby sitting.

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

So today I found myself in possession of two hours for myself during working hours. Time to catch-up with research. But it was impossible to make them profitable. Switching context is so difficult. Does this happen to you as well?

johncarlosbaez, to random
@johncarlosbaez@mathstodon.xyz avatar

David Bennett has a great video reminding us that outside the English-speaking world, most people don't call musical notes "C D E F G A B C". Instead they call them "do re mi fa so la si do", which is a system called "solfège" - or they use other systems.

But I was a bit shocked to see his map showing "no data" on what people do in most of Africa, or southeast Asia, or Korea, or Mongolia, or Pakistan, or Turkmenistan, or Uzbekistan.

Mind you, I don't hold it against him. He's an independent video-maker struggling to earn a living explaining music theory. He probably can't afford to spend hours and hours researching every country. But it saddens me to see this map.

I bet some of you here know the systems for naming notes in these greyed-out countries! Please tell us! And if you can find or make a better map, please do.

David Bennett's video is here:

https://www.youtube.com/watch?v=MVA8bgSBt5A

It has some nice info on the history of the solfège system and how it's used differently in English-speaking countries.

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@johncarlosbaez

It is also interesting to look at the etymology of the word solfège. It comes from the consecutive notes sol-fa.

(I only understand do-re-mi-fa-sol-la-si-do. When confronted with A-B-C-D-E-F-G, I have to count each time to translate, except for A and C.)

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@johncarlosbaez I wasn't talking about correspondence. Just notation.

christianp, to random
@christianp@mathstodon.xyz avatar

lost an hour to trying to get stabilisers on the boy's bike.
Difficulty: don't have the instructions, missing the bolts to attach them.

I had some small bolts that fitted, so finally got them on, but now the chain drags on the chain guard, so it mustn't be on quite correctly. Will have another look later.

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@christianp I remember a similar experience years ago!

ColinTheMathmo, to random
@ColinTheMathmo@mathstodon.xyz avatar

Ok peeps, What's this? Some sort of Chinese vegetable?

MartinEscardo, (edited )
@MartinEscardo@mathstodon.xyz avatar

@ColinTheMathmo Looks like what in Brazil is called "chuchu".

(I hated it as a child, but I haven't had a chance to try it again since.)

MartinEscardo, to random
@MartinEscardo@mathstodon.xyz avatar

How does topology show up in computation? An introduction from first principles.

Topology is the branch of mathematics that studies the notion of continuous function, and then everything that follows from that, and, more importantly, that, in the first place, sets the scene to be able to define the notion of continuity in full generality.

Originally, the notion of continuity was used (without a definition!) for functions ℝ → ℝ. At some point in the 19th century we had a definition.

And then people considered continuity of more general functions, e.g. ℝⁿ → ℝ, or C(ℝ) → ℝ where C(ℝ) is the set of all continuous functions ℝ → ℝ, and much more.

One interesting example, for computation, is the Cantor set (or Cantor space).

One way to describe it is as a subset of ℝ (https://en.wikipedia.org/wiki/Cantor_set), which you probably have seen as Cantor's third-middle set.

An isomorphic copy (or homeomorphic copy, as topologists would say) that often occurs in computation is as infinite binary sequences.

Technically, this is "the topological product of countably many copies of the discrete space {0,1}". One aim of this discussion is to make this technical definition more understandable if you don't have a background in Topology.

Consider a computer that keeps reading 0's and 1's and outputting 0's and 1's forever. For example, the program can be

while (true) {

b := read a binary digit;
print (1-b);
}

This program is an example of a continuous function from the Cantor space to the Cantor space.

1/

johncarlosbaez, (edited ) to random
@johncarlosbaez@mathstodon.xyz avatar

Many people tried to create a 12-tone scale where the frequency ratios are simple fractions built from the primes 2, 3 and 5. Kepler, Mersenne, Newton and Euler all tried their hand at it! But there are some choices.

This picture shows the most popular choice, which just happens to be Newton's. It has a beautiful up-down symmetry. To go up from the bottom you multiply by various numbers. Dividing by these same numbers takes you down from the top of the scale!

Some choices not taken are shown in grey. Other people used these other choices.

Nowadays most music is in 'equal temperament', with just one size of space between neighboring notes:

• the equal-tempered semitone, 2^(1/12) ≈ 1.05946….

But this scale has three:

• the diatonic semitone, 16/15 = 1.0666…

• the greater chromatic semitone, 135/128 = 1.0546875

• the lesser chromatic semitone, 25/24 = 1.041666…

There's also a tiny gap:

• the diaschisma, 2048/2025 ≈ 1.011358…

Hey, wait! Actually this scale has 13 tones! I tried to trick you into thinking it had 12. But to get 12, you need to leave out one of the two tones separated by the diaschisma. Both these tones are very close to the tritone. Pick one! Either way, you destroy the up-down symmetry.

(1/3)

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@johncarlosbaez @BartoszMilewski @julesh

I am going to ask a friend to has (or had, according to the above theory) absolute pitch, to see whether he considers that he is losing it.

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@johncarlosbaez I guess 54. He is in Edinburgh in the School of Informatics, by the way.

ionica, to random
@ionica@mathstodon.xyz avatar

To celebrate being on this lovely server for a year, I set up a monthly support payment to Mathstodon. Slightly bummed out that I did not score number 1729, but let this be an encouragement to others!

And many thanks to @christianp and @ColinTheMathmo for all their work on running things smoothly here!

MartinEscardo,
@MartinEscardo@mathstodon.xyz avatar

@ionica @christianp @ColinTheMathmo

I've been a financial supporter for about a year, and I don't regret it.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • morbius
  • Egalitarianism
  • tacticalgear
  • normalnudes
  • Youngstown
  • NeutralPolitics
  • osvaldo12
  • oldschoolgamer
  • rhentai
  • everett
  • ethstaker
  • InstantRegret
  • DreamBathrooms
  • slotface
  • kopitiam
  • cisconetworking
  • OmnivoreApp
  • Leos
  • GTA5RPClips
  • Durango
  • cubers
  • Kemonomimi
  • TeamSpeak
  • tester
  • lostlight
  • modclub
  • smallboobs
  • relationshipadvice
  • All magazines