我正在研究作业的转换问题,并且是完整的Haskell新手,所以请耐心等待。在其中之一上,它要求我们尝试使函数的类型为:
fc :: (Bool, [Char]) -> Int -> Integer -> [Bool]
不用担心实际功能是做什么的。这些函数将不会运行,它只是测试是否可以正确转换类型。到目前为止,我能得到的最远的是:
fc :: (Bool, [Char]) -> Int
fc (x, y) = ord (head y)
我把它变成一个地方Int
。当我尝试Integer
使用toInteger
功能将其转换为时,它给了我:
Couldn't match expected type `Int -> Integer'
with actual type `Integer'
In the return type of a call of `toInteger'
Probable cause: `toInteger' is applied to too many arguments
In the expression: toInteger (ord (head y))
对新手有什么提示吗?
编辑:我一直在尝试,以供参考,是:
fc :: (Bool, [Char]) -> Int -> Integer
fc (x, y) = toInteger (ord (head y))
我得到上面的错误。
您的类型签名错误。如果转换某些内容,则无法将其写入类型签名。只有最后一个是返回类型。其他是参数类型。请遵循以下步骤:
fc::(Bool,[Char])->Integer
fc (x,y) = toInteger . ord . head $ y
fc::(Bool,[Char])->Int->Integer--
fc (x,y) n = if n == w then n else w
where w = toInteger . ord . head $ y
编辑:其他人提到如果您的老师期望它是绝对正确的。但是转换不会在类型符号中进行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句