字符列表与Idris中的字符串不同吗?
在Haskell中,以下内容将打印“hello”:字符列表与Idris中的字符串不同吗?,idris,Idris,在Haskell中,以下内容将打印“hello”:putStrLn(['h','e','l','l','o']),但是,这会导致Idris中的编译错误: 48 | main = do | ~~ ... When checking right hand side of main with expected type IO () When checking an application of function Prelude.Interactive.putStr
putStrLn(['h','e','l','l','o'])
,但是,这会导致Idris中的编译错误:
48 | main = do
| ~~ ...
When checking right hand side of main with expected type
IO ()
When checking an application of function Prelude.Interactive.putStrLn:
Can't disambiguate since no name has a suitable type:
Prelude.List.::, Prelude.Stream.::
我怀疑这是因为
String
是Idris中内置的,而不是Haskell中内置的。不过,在Idris中是否可以使用a类型类来将列表字符
视为字符串
(是字符串
类型类)?没错,字符串与Idris中的字符列表不同。但有些函数允许您将字符列表转换为字符串,反之亦然
将字符串转换为字符列表
函数将可折叠的字符转换为字符串
因此,要打印字符列表,您只需:
putStrLn $ pack ['h', 'e', 'l', 'l', 'o']