在路由部分,文章中说:
关联的数据类型是什么意思?它是指类型家族吗?我们可以看到RenderRoute类定义了一个关联的数据类型,为应用程序提供路由。
引用文章中的代码:
instance RenderRoute HelloWorld where
data Route HelloWorld = HomeR
deriving (Show, Eq, Read)
renderRoute HomeR = ([], [])
从以下内容可以看出,Route
是一种相关数据类型,是数据家族的一种。请参考维基的示例:
We define a type class whose instances are the types that we can use as keys in our generic maps:
class GMapKey k where data GMap k :: * -> * empty :: GMap k v lookup :: k -> GMap k v -> Maybe v insert :: k -> v -> GMap k v -> GMap k v
The interesting part is the associated data family declaration of the class. It gives a kind signature (here
* -> *
) for the associated data typeGMap k
- analogous to how methods receive a type signature in a class declaration.
type
而不是data
来定义,就像在https://ocharles.org.uk/posts/2014-12-12-type-families.html中展示的那样。 - softshippertype Content a
的定义,它是什么? - softshipper