我尝试使用我使用列表的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
制作类似于typechecks的表达式?或者我怎样才能以另一种方式实现这一目标?
答案 0 :(得分:3)
你非常接近,但你需要使用list 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)