Haskell: [String] to IO () -
i new haskell , trying list of values input , print 1 item out list each line.
func :: [string] -> io ()
i having trouble trying figure out how print out item in list, when list size 1.
func [] = return () func [x] = return x
i getting error message when trying compile file:
couldn't match expected type `()' actual type `string' in first argument of `return', namely `x' in expression: return x
i lost , have tried searching haven't found anything. thanks!
you can use form_
this:
func :: [string] -> io () func l = form_ l putstrln
if want write own version directly, have problems.
for empty list, have nothing create value of io ()
, can return.
for non-empty list want output line putstrln
, process rest of list. non-empty list of form x:xs
x
head of list , xs
tail. second pattern matches one-element list.
func [] = return () func (x:xs) = putstrln x >> func xs
Comments
Post a Comment