Haskell/Agda中的类型级别集

ser*_*ras 6 haskell dependent-type

我已经看到GHC的最新版本中支持类型级列表.但是,我需要为应用程序使用类型级别集,并且希望基于类型级别列表实现类型级别集合库.但我不知道从哪里开始:(

在Haskell中是否有任何支持类型级别集的库?

JJJ*_*JJJ 2

您可以使用HList包中的HList的HSet属性:

{-# LANGUAGE FlexibleInstances #-}

import Data.HList

class (HList l, HSet l) => ThisIsSet l where
  -- Here we have @l@ which is @HList@ _and_ @HSet@.
  test :: l

-- This is ok:

instance ThisIsSet HNil where
  test = hNil

-- And this:

instance ThisIsSet (HCons HZero HNil) where
  test = hCons hZero hNil

-- And this (HZero != HSucc HZero):

instance ThisIsSet (HCons HZero (HCons (HSucc HZero) HNil)) where
  test = hCons hZero (hCons (hSucc hZero) hNil)

-- This is an error since HSucc HZero == HSucc HZero:

instance ThisIsSet (HCons (HSucc HZero) (HCons (HSucc HZero) HNil)) where
  test = hCons (hSucc hZero) (hCons (hSucc hZero) hNil)
Run Code Online (Sandbox Code Playgroud)

要使用其他类型,您需要为它们编写HEq实例。