Answer the question
In order to leave comments, you need to log in
Why doesn't head work with strings in Haskell?
import Data.List
main :: IO()
main = do
word <- getLine
putStrLn(head word)
$ ghc Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )
Main.hs:6:19:
Couldn't match type `Char' with `[Char]'
Expected type: [String]
Actual type: String
In the first argument of `head', namely `word'
In the first argument of `putStrLn', namely `(head word)'
In a stmt of a 'do' block: putStrLn (head word)
head
must take an array of elements of any type ( head :: [a] -> a
), but a string is considered an array [Char]
, isn't it? Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question