AA
Size: a a a
AA
L
type Test = ListWith1' @[0,1,2,3] ElemAuto -- okНо это не сильно помогло:
type Test2 = ListWith1' @[0,4,2,3] ElemAuto -- error
type ListWith1' :: forall xs. Elem 1 xs -> ListWith1T xs
type family ListWith1' x where
ListWith1' Nowhere = TypeError (Text "test")
ListWith1' @xs x = ListWith1 @xs x
type ElemAuto :: forall x xs. Elem x xs
type family ElemAuto where
ElemAuto @x @xs = App (Count 1 x xs)
type family Count acc x xs :: Nat where
Count acc x (x:xs) = acc
Count acc x (y:xs) = Count (acc + 1) x xs
Count acc x '[] = 0
type App :: Nat -> Elem x xs
type family App n where
App 0 = Nowhere
App 1 = Here
App n = There (App (n-1))
:kind! Test2
Test2 :: ListWith1T '[0, 4, 2, 3]
= (TypeError ...)
i
А
DM
AA
[
AA