是否有一个库,它使用constrainds概括所有基本类型类来允许约束?
-
12-12-2019 - |
题
我们可以使用扩展约束kinds来扩展基本类型类的功能以允许约束。例如,我们可以制作一个unboxed矢量一个仿函数:
class Functor f where
type FunctorConstraint f x :: Constraint
type FunctorConstraint f x = ()
fmap :: (FunctorConstraint f a, FunctorConstraint f b) => (a -> b) -> f a -> f b
instance Functor VU.Vector where
type FunctorConstraint VU.Vector x = VU.Unbox x
fmap = VU.map
.
(参见这些博客
编辑:还有,是否有计划将此直接添加到基础上?它似乎不应该通过直接更新班级定义来打破任何其他东西。
解决方案
由于它听起来没有其他人有一个图书馆,我已经转换了我所做的一个名为constraindkinds和上传到github 。目前它非常简单,可能没有涵盖任何其他人的用例,但随时可以自由地改变或提交请求。
如果在将项目上传到ackage之前,我可能会等待更多的反馈。
不隶属于 StackOverflow