Sto provando a ricavare un'istanza Typeable
per i vincoli di tipo tupla. Vedere il seguente codice:Istanza tipizzabile per torsione di vincoli
{-# LANGUAGE ConstraintKinds, GADTs #-}
{-# LANGUAGE DataKinds, PolyKinds, AutoDeriveTypeable #-}
{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}
import Data.Proxy
import Data.Typeable
data Foo (p :: (*, *))
data Dict ctx where
Dict :: ctx => Dict ctx
deriving (Typeable)
deriving instance Typeable '(,)
deriving instance Typeable Typeable
deriving instance Typeable Show
works :: IO()
works = print (typeRep (Proxy :: Proxy (Foo '(Bool, Char))))
alsoWorks :: IO()
alsoWorks = print (typeRep (Dict :: Dict (Show Bool)))
fails :: IO()
fails = print (typeRep (Dict :: Dict (Show Bool, Typeable Bool)))
main :: IO()
main = works >> alsoWorks >> fails
Se si compila questo con -fprint-explicit-kinds
, viene dato il seguente errore:
No instance for (Typeable
(Constraint -> Constraint -> Constraint) (,))
Esiste un modo per ricavare un caso del genere? Tutto ciò che provo si rifiuta di disambiguare dal costruttore ★ -> ★ -> ★
.
Il messaggio di errore 'Nessuna istanza per (Typeable (Constraint -> Constraint -> Constraint) (,))' sembra implicare che un costruttore di tipi esista * internamente * in qualche modo. Se avesse solo un nome, potremmo ... –