Sing
使用GHC.TypeLits是否有任何开销?例如对于程序:
{-# LANGUAGE DataKinds #-}
module Test (test) where
import GHC.TypeLits
test :: Integer
test = fromSing (sing :: Sing 5)
GHC生成核心代码:
Test.test1 :: GHC.Integer.Type.Integer
[GblId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=0, Value=True,
ConLike=True, WorkFree=True, Expandable=True,
Guidance=IF_ARGS [] 100 0}]
Test.test1 = __integer 5
Test.test :: GHC.Integer.Type.Integer
[GblId,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=0, Value=True,
ConLike=True, WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(unsat_ok=True,boring_ok=True)}]
Test.test =
Test.test1
`cast` (<GHC.TypeLits.NTCo:SingI> <GHC.TypeLits.Nat> <5> ; (<GHC.TypeLits.TFCo:R:SingNatn
<5>> ; <GHC.TypeLits.NTCo:R:SingNatn
<5>>)
:: GHC.TypeLits.SingI GHC.TypeLits.Nat 5
~#
GHC.Integer.Type.Integer)
此代码是否等效于Test.test = __integer 5
并且值是否将在编译时计算?