这个星星在这个haskell代码中意味着什么? [英] What does the star mean in this haskell code?

查看:104
本文介绍了这个星星在这个haskell代码中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在unm-hip包中找到了这个代码。
So Pixel是一个函数吗?

I found this code in the unm-hip package. So Pixel is a function ?

class Imageable i where
  type Pixel i :: *
  rows :: i -> Int
  cols :: i -> Int
  ref  :: i -> Int -> Int -> (Pixel i)
  makeImage :: Int -> Int -> PixelOp (Pixel i) -> i
  pixelList :: i -> [Pixel i]
  pixelList i = [ ref i r c | r <- [0..(rows i - 1)], c <- [0..(cols i - 1)]]


推荐答案

使用的其他扩展在这个代码中(我起初没有注意到,因为缩进失去了)是关联类型。标准Haskell中的类型类可以指定类型必须支持的多个函数。有了关联类型,它可以另外指定类型和与类型关联的类型构造函数。

The other extension used in this code (which I didn't notice at first, since the indentation was lost) is associated types. A typeclass in standard Haskell can specify a number of functions that the type must support. With associated types, it can additionally specify types and type constructors that are associated with the type.

这意味着类型 i 它是一个可成像的实例(即,像图像一样)必须具有关联的像素类型像素i ,这必须是一个简单的类型(类型 * ),而不是类型构造函数。

Here, this means that a type i that is an instance of Imageable (i.e. behaves like an image) must have an associated pixel type Pixel i, and this must be a simple type (kind *), not a type constructor.

这篇关于这个星星在这个haskell代码中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆