user2807679
user2807679

Reputation: 11

function trouble not in scope: data constructor

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

Answers (2)

Thomas M. DuBuisson
Thomas M. DuBuisson

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

Alex
Alex

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

Related Questions