[Haskell-cafe] Why does this result in a runtime loop instead of a type error or typechecker loop?

Michael Snoyman michael at snoyman.com
Tue Jul 24 05:08:51 UTC 2018

It looks like you have an infinite loop created, where `hasLens = boolL`
and `boolL = hasLens`, and the two overlappable instances are each
fulfilling the constraints of the other instance.

On Tue, Jul 24, 2018 at 12:11 AM Theodore Lief Gannon <tanuki at gmail.com>

> λ. :set -XFlexibleContexts -XFlexibleInstances -XMultiParamTypeClasses
> -XUndecidableInstances
> λ. import RIO
> λ. import Data.Has
> λ. class HasBool a where boolL :: Lens' a Bool
> λ. instance {-#OVERLAPPABLE#-} HasBool a => Has Bool a where hasLens =
> boolL
> λ. instance {-#OVERLAPPABLE#-} Has Bool a => HasBool a where boolL =
> hasLens
> λ. runRIO () $ view boolL
> ^CInterrupted.
> The RIO environment () doesn't contain a Bool. I can see how the
> typechecker might get lost in this, but I can compile an equivalent
> program; it loops on execution.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180724/4e0f72fd/attachment.html>

More information about the Haskell-Cafe mailing list