[Haskell-cafe] Monad laws
Mateusz Kowalczyk
fuuzetsu at fuuzetsu.co.uk
Wed Jun 25 04:33:43 UTC 2014
On 06/25/2014 05:54 AM, Rafael Almeida wrote:
> Hello,
>
> You guys have been great taking my questions. Thank you. Now I have another
> one :)
>
> What can go wrong if I make an Monad instance but don't follow Monad rules
> (identity and associativity)? Sure it would be misleading for someone using
> the non-conforming class. They may make code that assume those laws,
> although they don't hold. However, could it make the compiler generate bad
> code
The compiler makes no assumption (at least that I know of) that laws are
followed. It should never generate ‘bad’ code (whatever that might mean)
anyway.
> or some standard functions to behave badly or even break?
Yes, namely they wouldn't do ‘the expected thing’ if they rely on the
laws. Also someone might be overeager and use RULES based on just
type-class laws.
> []'s
> Rafael
>
>
Basically, if you don't have a monad, don't make it an instance of
Monad, it defeats the whole point of having a typeclass expecting some
laws to be satisfied to begin with.
--
Mateusz K.
More information about the Haskell-Cafe
mailing list