Question

I'm trying to write a haskell program that takes in a string and returns a new string that only contains the vowels but I'm getting this error.

`Char' is applied to too many type arguments
In the type signature for `vowels': vowels :: Char a => a -> a

Here's my code:

vowels :: (Char a) => a -> a
vowels str = [ x | x <- str, x `elem` ['A','E','I','U','Y','O']]
Was it helpful?

Solution

Your type signature should be

vowels :: [Char] -> [Char]
vowels str = [ x | x <- str, x `elem` ['A','E','I','U','Y','O']]

or

vowels :: String -> String

In your code, (Char a) => ... indicates that the type a should be an instance of the typeclass Char. However, Char is a data type, not a type class which is why you get the error. Since you don't need any classes to implement this function you can just remove the constraint.

OTHER TIPS

Is this what you're trying to achieve?

vowels :: String -> [Char]
vowels = let
             y =  ['A','a','E','e','I','i','U','u','Y','y','O',o']
         in filter.(\x -> elem x y)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top