Reputation: 11
I am trying to write a function removeSpaces
that once handed a string it will remove any spaces found within it.
What I got so far is:
import Data.Char
removeSpaces :: [Char] -> [Char]
removeSpaces [] = []
removeSpaces xs = filter isAlpha xs
This however keeps giving me the message "not in scope: data constructor" with the pieces of the string that are before and after any spaces within the String
. Any help with this would be great.
Upvotes: 1
Views: 393
Reputation: 64740
It works fine:
$ echo "import Data.Char
> removeSpaces :: [Char] -> [Char]
> removeSpaces [] = []
> removeSpaces xs = filter isAlpha xs" > so.hs
$ ghci so.hs
GHCi, version 7.6.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( so.hs, interpreted )
Ok, modules loaded: Main.
*Main> removeSpaces "no spaces"
"nospaces"
*Main>
Upvotes: 1
Reputation: 650
That function looks fine although you don't need the case for the empty list as filter deals with that case.
import Data.Char
removeSpaces :: [Char] -> [Char]
removeSpaces xs = filter isAlpha xs
Can you give an example of how you are calling the function
Upvotes: 2