0
initials :: String -> String -> String
initials firstname lastname = [f] ++ ". " ++ [l] ++ "."
    where (f:_) = firstname
          (l:_) = lastname 

For this code. I got error

parse error on input `='

Why?

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Anders Lind
  • 4,542
  • 8
  • 46
  • 59
  • I didn't... http://codepad.org/LVecpglP The only error I think was the last line was not properly indented. After you corrected it... the parse error should go – A. K. May 06 '12 at 01:17

2 Answers2

4

You use a tab character before the where keyword. To GHC it looks like this:

␉       where␠(f:_)␠=␠firstname
␠␠␠␠␠␠␠␠␠(l:_)␠=␠lastname 

So, GHC thinks that the first line in the where block starts at column 14 (tab counts for 8 columns iirc) while the second line starts at column 9, which causes the error.

You should use a good text editor that converts tabs into 4 spaces for you.

dflemstr
  • 25,947
  • 5
  • 70
  • 105
4

By the way, you don't need the helper functions, you can directly pattern match on the arguments

initials :: String -> String -> String
initials (f:_) (l:_) = [f,'.',' ',l,'.']
Landei
  • 54,104
  • 13
  • 100
  • 195