Tôi muốn viết mã mà sẽ đầu ra:Chuỗi suy trong Haskell
length [1,2,3] => 3
Trong Ruby, tôi có thể làm điều đó thích:
puts "length [1,2,3] => #{[1,2,3].length}"
Sau thử là Haskell thất bại ...
Prelude Data.List> print "length [1,2,3]"
"length [1,2,3]"
Prelude Data.List> print (length [1,2,3])
3
Prelude Data.List> print "length [1,2,3]" (length [1,2,3])
<interactive>:1:0:
Couldn't match expected type `Int -> t'
against inferred type `IO()'
In the expression: print "length [1,2,3]" (length [1, 2, 3])
In the definition of `it':
it = print "length [1,2,3]" (length [1, 2, 3])
Prelude Data.List>
BTW, sử dụng in trên một chuỗi sẽ in bằng dấu ngoặc kép (và thoát). Hãy thử putStr hoặc putStrLn để in chuỗi như là. –