The vote on this output option has moved here.
Haskell has a very strong type system, so there is a type called Maybe
to work around some restrictions.
The Maybe type is defined as follows:
data Maybe a = Just a | Nothing deriving (Eq, Ord)
It allows the programmer to specify something may not be there.
From the Haskell wiki.
Essentially, instead of erroring out, a function can return a Maybe
that is either a Just x
where x
is the intended output or it can return Nothing
, which indicates that there is no possible output.
One example is the second solution in one of my answers. As you can see, in the output, the answer asked for is Just
prefixed.
This can be fixed by applying foldl1 seq
to the result, which I think is the golfiest way to do this.
Is outputting a Maybe
valid?
Maybe we can allow this...
x
ornil
or something equivalent. \$\endgroup\$Maybe
as mentioned in the Haskell wiki is not the way it is defined. Trydata Mby a = Jst a | Nope deriving (Eq, Ord)
and then(+1) <$> Jst 41
which will complain thatMby
is not an instance ofFunctor
whereas the realMaybe
certainly is and it implements a lot of other classes too (check:info Maybe
inghci
).. \$\endgroup\$