将自定义类型转换为字符串
Converting self-defined type to a string
我正在开发一个函数 goPosition
来将我的自定义数据类型:Position
转换为 String
。虽然我觉得我说得有道理,但是编译器不同意我的看法。
我的数据类型是:
data Position = Pos Char Int
我的输入是:
goPosition (Pos ('H' 3))
编译器 returns :
<interactive>:6:15:
Couldn't match expected type ‘Position’
with actual type ‘Int -> Position’
Probable cause: ‘Pos’ is applied to too few arguments
In the first argument of ‘goPosition’, namely ‘(Pos ('H' 3))’
In the expression: goPosition (Pos ('H' 3))
<interactive>:6:20:
Couldn't match expected type ‘Integer -> Char’
with actual type ‘Char’
The function ‘'H'’ is applied to one argument,
but its type ‘Char’ has none
In the first argument of ‘Pos’, namely ‘('H' 3)’
In the first argument of ‘goPosition’, namely ‘(Pos ('H' 3))’
也许是我输入错误的问题?我真的不确定。任何帮助将不胜感激!
是的,我输入错了。应该是 goPosition (Pos 'H' 3)
我正在开发一个函数 goPosition
来将我的自定义数据类型:Position
转换为 String
。虽然我觉得我说得有道理,但是编译器不同意我的看法。
我的数据类型是:
data Position = Pos Char Int
我的输入是:
goPosition (Pos ('H' 3))
编译器 returns :
<interactive>:6:15:
Couldn't match expected type ‘Position’
with actual type ‘Int -> Position’
Probable cause: ‘Pos’ is applied to too few arguments
In the first argument of ‘goPosition’, namely ‘(Pos ('H' 3))’
In the expression: goPosition (Pos ('H' 3))
<interactive>:6:20:
Couldn't match expected type ‘Integer -> Char’
with actual type ‘Char’
The function ‘'H'’ is applied to one argument,
but its type ‘Char’ has none
In the first argument of ‘Pos’, namely ‘('H' 3)’
In the first argument of ‘goPosition’, namely ‘(Pos ('H' 3))’
也许是我输入错误的问题?我真的不确定。任何帮助将不胜感激!
是的,我输入错了。应该是 goPosition (Pos 'H' 3)