字符列表与 Idris 中的字符串不同吗?

Are character lists different than Strings in 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.putStrLn:
        Can't disambiguate since no name has a suitable type:
                Prelude.List.::, Prelude.Stream.::

我怀疑这是因为 String 是 Idris 的内置函数,而不是 Haskell。仍然,可以在 Idris 中使用类型 class 将 List Char 视为 String 的实例(String 是类型 class 吗)?

没错,字符串与 Idris 中的字符列表不同。但是有些函数允许您将字符列表转换为字符串,反之亦然。

unpack 将字符串转换为字符列表

pack 函数将一个可折叠的字符转换为一个字符串

因此,为了打印字符列表,您只需要:

putStrLn $ pack ['h', 'e', 'l', 'l', 'o']