In Haskell in Depth, Chapter 11, there's an example aimed at avoiding character escaping in GHCi, which is what happens automatically when you enter print "ë", as it'll be printed like "\235" instead of "ë".
Part of the solution relies on this code:
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE UndecidableInstances #-}
data UnescapingChar = UnescapingChar { unescapingChar :: Char }
type family ToUnescapingTF (a :: k) :: k where
{- 1 -} ToUnescapingTF Char = UnescapingChar
{- 2 -} ToUnescapingTF (t b :: k) = (ToUnescapingTF t) (ToUnescapingTF b)
{- 3 -} ToUnescapingTF a = a
which would fail to compile for me on line 1 with error
• Expected kind ‘k’, but ‘Char’ has kind ‘*’
• In the first argument of ‘ToUnescapingTF’, namely ‘Char’
In the type family declaration for ‘ToUnescapingTF’ [GHC-25897]
and, if I comment that out, it fails on line 2 with
• Expected kind ‘k’, but ‘t’ has kind ‘k -> k’
• In the first argument of ‘ToUnescapingTF’, namely ‘t’
In the type ‘(ToUnescapingTF t) (ToUnescapingTF b)’
In the type family declaration for ‘ToUnescapingTF’ [GHC-25897]
It turns out it failed because I'm building with GHC2024, whereas the examples from the book are built with Haskell2010. Trying the extensions included in Haskell2010 one by one with my GHC2024 project, I've found I can compile if I also include CUSKs (at which point it looks like I can drop PolyKinds).
Now, I'm not sure including CUSKs is the way to go, because I read this about it:
NB! This is a legacy feature, see
StandaloneKindSignaturesfor the modern replacement.
but StandaloneKindSignatures doesn't mention CUSKs at all, other than in saying that StandaloneKindSignatures implies NoCUSKs.
How can I go about it?