[Haskell-cafe] Mild confusion around type family

adam vogt vogt.adam at gmail.com
Sat Jun 20 15:34:58 UTC 2015

On Jun 19, 2015 2:29 PM, "Richard Eisenberg" <eir at cis.upenn.edu> wrote:
> With a closed family, you could always do something like this:
> > type family Error (msg :: Symbol)     -- no instances!
> > type family Sub a b where
> >   -- real work
> >   Sub a b = Error "Sub is undefined here"
> Would that help? It still doesn't immediately error (there's no way to do
that currently), but it's perhaps more telling to have an error string.

Ghc does error out right away if you give it an infinite loop:

type family Fail (x::k) (a :: *) where
  Fail x a = Fail x (Fail "don't raise the context stack please" a)

-- defining f leads to compile failure, and the message includes the "msg"
f :: Fail "msg" ()
f = undefined

But it would be nice to have a less hacky solution, especially as this one
gives error messages that suggest giving the type checker more resources.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150620/5a20f6ef/attachment.html>

More information about the Haskell-Cafe mailing list