0

I'm trying to compile this function:

fff [] _ = []
fff (x:xs) ys
   | r == [] = xs1
   | otherwise ys ++ xs1
   where r = filter (x<) ys 
         xs1 = fff xs ys

But I get this error:

Test.hs:14:4: parse error on input `where'

Failed, modules loaded: none.

Any help to solve it?

Thanks,
Sebastián.

1 Answer 1

2

You missed the required = after otherwise.

By the way, r == [] better be replaced by the more general null r.

Try this:

fff [] _ = []
fff (x:xs) ys
    | r == [] = xs1
    | otherwise = ys ++ xs1
    where r = filter (x<) ys 
          xs1 = fff xs ys
Sign up to request clarification or add additional context in comments.

1 Comment

The better reason to use null over == [] is because == [] requires that your list be of type Eq a => [a], where null :: [a] -> Bool, so null works on all lists, not just lists of Eq a => a values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.