gpt4 book ai didi

haskell - 方程有不同数量的参数

转载 作者:行者123 更新时间:2023-12-02 21:12:17 25 4
gpt4 key购买 nike

我创建了这些数据类型来表示吉他标签,并且我正在尝试编写 show 函数将它们打印为真正的吉他标签。 数据不是我的专长,我在匹配类型时遇到了困难。

错误是

Equations for `show' have different numbers of arguments In the instance declaration for GHC.Show.Show Tabs.Chord'

代码:

type Strings = Int

data Fret = None | Note Int

instance Show Fret where
show None = "-"
show (Note a) = show a

data Chord = EmptyChord Strings | Chord [Fret]

instance Show Chord where
show EmptyChord a = init $ take (a * 2) ['-', '\n' ..]
show Chord (x : xs) = x : '\n' : show xs

最佳答案

第二个实例需要更多括号:

instance Show Chord where
show (EmptyChord a) = init $ take (a * 2) ['-', '\n' ..]
show (Chord (x : xs)) = x : '\n' : show xs

关于haskell - 方程有不同数量的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31307713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com