Viene visualizzato un errore quando si tenta di definire un sinonimo di modello basato su su un GADT che ha un elenco di tipo livello.Il sinonimo di Pattern non può unificare i tipi all'interno dell'elenco a livello di tipo
sono riuscito a bollire fino a questo esempio:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PatternSynonyms #-}
module Example where
data L (as :: [*]) where
L :: a -> L '[a]
pattern LUnit = L()
Mi dà:
Example.hs:11:17:
Couldn't match type ‘a’ with ‘()’
‘a’ is a rigid type variable bound by
the type signature for Example.$bLUnit :: (t ~ '[a]) => L t
at Example.hs:11:17
Expected type: L t
Actual type: L '[()]
In the expression: L()
In an equation for ‘$bLUnit’: $bLUnit = L()
Example.hs:11:19:
Could not deduce (a ~())
from the context (t ~ '[a])
bound by a pattern with constructor
L :: forall a. a -> L '[a],
in a pattern synonym declaration
at Example.hs:11:17-20
‘a’ is a rigid type variable bound by
a pattern with constructor
L :: forall a. a -> L '[a],
in a pattern synonym declaration
at Example.hs:11:17
In the pattern:()
In the pattern: L()
Questo è un bug, o sto facendo qualcosa di sbagliato?
Penso che tu abbia almeno bisogno di una firma di modello, ma la documentazione non sembra rendere molto chiaro se sia possibile rendere il tipo di un sinonimo di modello per un costruttore GADT come polimorfico come il costruttore stesso. – dfeuer
dfeuer: aha, grazie – rampion