Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this context mean: (Monad m, (~) * a ())?

Tags:

haskell

I've found the following class instance : (Monad m, (~) * a ()) => LaTeXC (LaTeXT m a), but can't quite understand its context.

What does (~) * a () mean? Where can I read about it?

like image 923
Dmitry Polyanitsa Avatar asked Jan 17 '15 17:01

Dmitry Polyanitsa


1 Answers

(~) is type-level equality (you could write it as some variant of = or ==, but the opinion was that this notation already had enough different meanings that introducing another would be confusing). * is the kind of types. So (~) * is the assertion that two (inhabitable) types are equal. In other words, the instance could also be written like this:

instance Monad m => LaTeXC (LaTeXT m ())

Why wasn't it? Well, it's a question of inference. The way it was written makes the compiler choose this instance even if it doesn't (yet) know that the final argument to LaTeXT is (), then forces that, whereas the proposed alternative instance would simply complain.

like image 82
Daniel Wagner Avatar answered Sep 19 '22 22:09

Daniel Wagner