Some time after I asked What happens to you if you break the monad laws? I stumbled across this unexplained phrase on Haskell Wiki, on a page about Safely running untrusted haskell code:
"creating class instances that violate assumed laws (cf EvilIx)"
as an example of an exploit that was possible against lambdabot.
Since lambdabot uses GHC presumably this was a bug (or feature) of GHC making assumptions about class laws. Does anyone remember what those are? And has this ever (or could it possibly) happen acidentally?
(googling for "haskell +Evillx" turns up no hits).
Arrays use Ix
to manage bounds. They trust that Ix
does what it says. If it doesn't, you can trick the array mechanisms into accessing memory locations that aren't theirs.
cf EvilIx
: http://www.haskell.org/pipermail/haskell-cafe/2006-December/019994.html
If we think of a monad as modelling side effects, a type claiming to be a monad but not obeying the laws can result in effects occurring in the wrong order or the wrong number of times.
A classic example of this is ListT
, the list monad transformer.
The original implementation didn't satisy the monad laws.
The "ListT Done Right
wiki page has some simple examples of usage of ListT
in the section called
"Examples".
You can see the difference between what these programs do
when you run them with the original
implementation that violates the laws, and
when you run them with a replacement that satisfies the laws.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With