Синоним шаблона не может объединять типы в списке на уровне типов

Я получаю сообщение об ошибке при попытке определить синоним шаблона на основе GADT, который имеет список уровня типа.

Мне удалось свести это к следующему примеру:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PatternSynonyms #-}
module Example where

data L (as :: [*]) where
  L :: a -> L '[a]

pattern LUnit = L ()

Дает мне:

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 ()

Это ошибка или я что-то не так делаю?

1 ответ

Решение

Благодаря комментарию dfeuer и этому тикету, я смог получить пример кода для компиляции, добавив сигнатуру типа в определение шаблона:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PatternSynonyms #-}
module Example where

data L (as :: [*]) where
  L :: a -> L '[a]

pattern LUnit :: L '[()]
pattern LUnit = L ()

Что также хорошо обобщает полиморфные узоры

data F (fs :: [* -> *]) a where
  F :: f a -> F '[f] a

pattern FId :: a -> F '[Identity] a
pattern FId a = F (Identity a)
Другие вопросы по тегам