Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell “的含义;“类型”;类型类声明中的声明_Haskell_Type Families_Associated Types - Fatal编程技术网

Haskell “的含义;“类型”;类型类声明中的声明

Haskell “的含义;“类型”;类型类声明中的声明,haskell,type-families,associated-types,Haskell,Type Families,Associated Types,我刚刚发现了这段代码: -- | Gathers common slice operations. class Slice a where type Loc a sliceEvents :: a -> [ResolvedEvent] -- ^ Gets slice's 'ResolvedEvent's. sliceDirection :: a -> ReadDirection -- ^ Gets slice's reading directi

我刚刚发现了这段代码:

-- | Gathers common slice operations.
class Slice a where
    type Loc a

    sliceEvents :: a -> [ResolvedEvent]
    -- ^ Gets slice's 'ResolvedEvent's.
    sliceDirection :: a -> ReadDirection
    -- ^ Gets slice's reading direction.
    sliceEOS :: a -> Bool
    -- ^ If the slice reaches the end of the stream.
    sliceFrom :: a -> Loc a
    -- ^ Gets the starting location of this slice.
    sliceNext :: a -> Loc a
    -- ^ Gets the next location of this slice.
    toSlice :: a -> SomeSlice
    -- ^ Returns a common view of a slice.

我不明白
type Loc a
在做什么…

Loc a
是一个关联类型,这是一种声明与类实例关联的类型族实例的方法。由
Loc a
表示的类型由
a
的类型确定,并在实例中指定:例如

instance Slice Foo where
    type Loc Foo = Bar
    ...
在类声明中出现
loca
的地方,它将被实例中相应的类型替换-因此
Foo
的实例函数如下所示

sliceEvents :: Foo -> [ResolvedEvent]
...
sliceFrom :: Foo -> Bar
...
关联类型还可以通过提供类约束在类声明之外的其他函数中使用:例如

myFunction :: (Slice a) => a -> Loc a

这不是标准的Haskll 2010;它是GHC的一种更具异国情调的语言扩展。(关联类型,我想…)是的,这就是名字。。。。。这是扩展。。。{-#语言类型族{-}