I was just looking at the type of map :: (a -> b) -> [a] -> [b]
and just the shape of this function made me wonder whether we could see the list forming operator [ ] as obeying various axioms common to normal modal logics (e.g, T, S4, S5, B), since we seem to have at least the K-axiom of normal modal logics, with [(a -> b)] -> [a] -> [b]
.
This leads to my question: are there familiar, interesting operators or functors in Haskell which have the syntax of modal operators of a certain kind, and which obey the axioms common to normal modal logics (i.e, K, T, S4, S5 and B)?
This question can be sharpened and made more specific. Consider an operator L
, and its dual M
. Now the question becomes: are there any familiar, interesting operators in Haskell with some of the following properties:
(1) L(a -> b) -> La -> Lb
(2) La -> a
(3) Ma -> L(M a)
(4) La -> L(L a)
(5) a -> L(M a)
It would be very interesting to see some nice examples.
I've thought of a potential example, but it would be good to know whether I am correct: the double negation translation with L
as not not
and M
as not
. This translation takes every formula a
to its double negation translation (a -> ⊥) -> ⊥
and, crucially, validates axioms (1)-(4), but not axiom (5). I asked a question here https://math.stackexchange.com/questions/2347437/continuations-in-mathematics-nice-examples and it seems the double negation translation can be simulated via the continuation monad, the endofunctor taking every formula a
to its double negation translation (a -> ⊥) -> ⊥
. There Derek Elkins notes the existence of a couple of double negation translations corresponding, via the Curry-Howard isomorphism, to different continuation-passing style transforms, e.g. Kolmogorov's corresponds to the call-by-name CPS transform.
Perhaps there are other operations that can be done in the continuation monad via Haskell which can validate axioms (1)-(5).
(And just to eliminate one example: there are clear relations between so-called Lax logic https://www.sciencedirect.com/science/article/pii/S0890540197926274 and Monads in Haskell, with the return operation obeying the laws of the modal operator of this logic (which is an endofunctor). I am not interested so much in those examples, but in examples of Haskell operators which obey some of the axioms of modal operators in classical normal modal logics)
a
s tob
s. – Someway[a -> b] -> [a] -> [b]
is the type of(<*>)
specialized to the[]
instance ofApplicative
. – Keck(<*>) :: [a -> b] -> [a] -> [b]
, and also for the "function modality" we have(<*>) :: (e -> (a -> b)) -> (e -> a) -> (e -> b)
which is the well-known K combinator. Probably just coincidence that they share the K name, though. ;-) – Wheat<*>
obey any of the other axioms of normal modal logics? – GinnyL
sure as heck looks like a comonad, not sure what a correspondingM
would be offhand. But e.g. known comonads such as nonempty lists ofa
, pairs(w,a)
would satisfy. – Mimeographextract
is like (2) above (the T-axiom in modal logic),duplicate
is like (4) (the S4 axiom). A simple example of an operator for (3) would takeM
to denoteFalse
andL
to denoteTruth
, and this interpretation (obviously) works for some of the other examples. – Ginnya
, pairs(w,a)
would satisfy what, sorry? – GinnyComonadApply
for some modal logic. – GunasL
asnot not
andM
asnot
validates all the axioms above. I asked this question here math.stackexchange.com/questions/2347437/… in which I argued the double negation translation was an example of the continuation monad. The endofunctor in this case would take every formulaa
to its double negation translation(a -> ⊥) -> ⊥
. – Ginnya -> not (not (not a))
which seems a touch disturbing. – SternM
≈Monad
andL
≈ComonadApply
(#1:(Applicative f) => f (a -> b) -> f a -> f b
; #2:extract :: (Comonad f) => f a -> a
; #4:duplicate :: (Comonad f) => f a -> f (f a)
) or possiblyMonadTrans
(#3:lift :: (MonadTrans t, Monad m) => m a -> t (m a)
; #5:instance (MonadTrans t, Monad m) => Monad (t m) where return :: a -> t (m a)
). But I’ve only really worked with epistemic modal logic (□ = “known to be true”, ◇ = “not known to be false”), not too familiar with modal logic in general. – Rambert(Applicative f) => f (a -> b) -> f a -> f b
whenf
is a comonad? If it does, then a Comonadic operator behaves syntatically like the necessity operator of S4 modal logic (the modal logic intertranslatable with intuitionistic logic via Godel's famous translation). Do monad transformers obey any of the other axioms I listed in my question? – Ginny<*>
is the S combinator though, not K. – Zippy