我試圖得到這個工作:如何爲矢量矢量創建一個Maybe等價物?
type CharVector = V.Vector Char
type CharMatrix = V.Vector CharVector
data MaybeCharMatrix =
Nothing
| CharMatrix
但我不能做以下事情:
1)模式匹配
test :: MaybeCharMatrix -> Int
test Nothing = -1 -- Doesn't matter, is just to illustrate
test <something> = ? -- Somehow be able to do: cols <something> * rows
2)推導show instance:
instance Show MaybeCharMatrix where
show Nothing = ""
show <something> = "Cols: " ++ cols <something> ++ ", Rows: " ++ rows <something>
這是如何實現的?有沒有其他有效的方法來做到這一點?
'data MaybeCharMatrix = Nothing | CharMatrix' - 在這裏CharMatrix是一個構造函數AFAIK,**不是**也稱爲'CharMatrix'的類型。 – immibis