[英]Type-level sets in Haskell / Agda
I've seen that in the latest versions of GHC there's support for type-level lists. 我已经看到,在最新版本的GHC中支持类型级别列表。 However, I need to work with type-level sets for an application, and would like to implement a type-level set library based on type-level lists.
但是,我需要为应用程序使用类型级别集,并且想基于类型级别列表实现类型级别集库。 But I don't know where to start :(
但是我不知道从哪里开始:(
Is there any library supporting type-level sets in Haskell? Haskell中是否有任何支持类型级别集的库?
You can use HSet property for HList 's from HList package: 您可以从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)
for working with other types you need to write HEq instances for them. 要使用其他类型,您需要为它们编写HEq实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.