如何将列表与 Haskell 单例库一起使用?

How to use lists with the Haskell singletons library?

我正在尝试使用 singletons 库创建一个类型,其中我使用了一个列表:

import Data.Singletons.TH (singletons)

$(singletons [d|

    data LLVMType
        = IntegerType
        | FloatType
        | FunctionType { argumentTypes :: [LLVMType] }

    |])

foo :: SLLVMType ('FunctionType '[ 'IntegerType ])
foo = ???

我试图让 foo 成为:SFunctionType [SIntegerType],但是它导致了这个错误:

• Couldn't match expected type ‘Data.Singletons.Sing '['IntegerType]’
              with actual type ‘[Data.Singletons.Sing 'IntegerType]’
• In the first argument of ‘SFunctionType’, namely ‘[SIntegerType]’
  In the expression: SFunctionType [SIntegerType]
  In an equation for ‘foo’: foo = SFunctionType [SIntegerType]

如何为 foo 创建一个可以进行类型检查的表达式?或者我怎样才能以其他方式实现这一目标?

Github repo with the code.

你很接近,但你需要使用列表singletons

{-# language TemplateHaskell, DataKinds, GADTs, TypeFamilies #-}
module SingList where

import Data.Singletons.TH (singletons)
import Data.Singletons.Prelude.List (Sing (SNil, SCons))

$(singletons [d|

    data LLVMType
        = IntegerType
        | FloatType
        | FunctionType { argumentTypes :: [LLVMType] }

    |])

foo :: SLLVMType ('FunctionType '[ 'IntegerType ])
foo = SFunctionType (SCons SIntegerType SNil)