Filtering Nothing and unpack Just

haskell

Solution

You don't need to write `filterJust` function. It is already in `base` and it is called `catMaybes`:

Also, you can see better way to define this function:

catMaybes :: [Maybe a] -> [a]
catMaybes ls = [x | Just x <- ls]

So all you need to do is just add `import Data.Maybe (catMaybes)` into your module.

Here this function is using the "MonadFail sugar" design pattern for lists. You can read more about it and other patterns in the following blog post:

- https://kowainik.github.io/posts/haskell-mini-patterns#monadfail-sugar

Problem

I'm having trouble with this program. ``` filterJust :: [Maybe a] -> [a] filterJust [] = [] filterJust x = map fromJust (filter (isJust) x) ``` but ghci keeps reporting this EDIT: I don't want to use any additional module so i made this: ``` filterJust :: [Maybe a] -> [a] filterJust x = map unpack (filter (Nothing /=) x) unpack (Just a) = a ``` and i get this message and i dont understand why. I should be able to use Eq functions without importing anthing right?

Original source