1
我想创建一个Pixel类型,并使其成为Eq和Show类的一个实例。但是,我一直在阅读很多地方的信息,并对此感到困惑。Haskell中的类型参数
下面是关于类型的一些信息我需要创建:
我必须存储两个数字(像素的位置,从0到255之间的值)。 如果它们具有相同的值,则无论它们的位置如何,两个像素都是相等的。 对于Show实例,我需要打印位置和值。
这是我尝试在此:
type position = Float
type greyScale = Int
type Pixel = (position, greyScale)
instance Eq Pixel where
greyScale == greyScale = True
instance Show Pixel where
show position = position
show greyScale = greyScale
这是做正确的方式?
而对于更多的例子:[learnyouahaskell.com](http://learnyouahaskell.com/making-our-own-类型和 - 类型类) – phg