我发现我无法使用Data.Singletons.TH
中的函数为其中涉及Text
/ Symbol
s的任何类型创建单例。
Demote Symbol = Text
,因此这显然是singletons
的预期用例,但是无论我尝试使用哪一个,都会出现错误(如下)。当我用Text
或Symbol
替换String
时,错误消息是相同的,但用Text
或Symbol
替换了String
。
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Lib where
import Data.Singletons.TH
import Data.Text (Text)
$(singletons [d|
data MyType = MyType Text Text
|])
导致:
src/Lib.hs:14:3: error:
• Could not deduce: Demote Text ~ Text
from the context: a ~ 'MyType n n1
bound by a pattern with constructor:
SMyType :: forall (n1 :: Text) (n2 :: Text).
Sing n1 -> Sing n2 -> Sing ('MyType n1 n2),
in an equation for ‘fromSing’
at src/Lib.hs:(14,3)-(16,4)
• In the first argument of ‘MyType’, namely ‘(fromSing b_a7ip)’
In the expression: (MyType (fromSing b_a7ip)) (fromSing b_a7iq)
In an equation for ‘fromSing’:
fromSing (SMyType b_a7ip b_a7iq)
= (MyType (fromSing b_a7ip)) (fromSing b_a7iq)
|
14 | $(singletons [d|
| ^^^^^^^^^^^^^^...
src/Lib.hs:14:3: error:
• Couldn't match expected type ‘Text’
with actual type ‘Demote Text’
• When checking that the pattern signature: Demote Text
fits the type of its context: Text
In the pattern: b_a7is :: Demote Text
In the pattern:
MyType (b_a7is :: Demote Text) (b_a7it :: Demote Text)
|
14 | $(singletons [d|
| ^^^^^^^^^^^^^^...