Got stuck again while trying to learn some Haskell. What I'm trying to do is implementing a combined head/tail
method for lists with error handling. The signature must look like this:
head' :: MonadPlus m => [a] -> m (a,[a])
However I'm a bit lost at how error handling with MonadPlus works. I tried the following:
head' xs = if (length xs > 0) then Just(head xs, tail xs) else Nothing
but it complains: Expected type: m (a, [a]) Actual type: Maybe (a, [a]). Just for fun I also tried:
head' xs = if (length xs > 0) then Just(head xs, tail xs) else Nothing `mplus` Nothing
but not only does that look redundant, it also does not work either.
Any hints appreciated!