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?
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?
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.
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,'.']