[Haskell-beginners] Early return in IO monad
Brent Yorgey
byorgey at seas.upenn.edu
Sat Aug 31 20:23:16 CEST 2013
On Sat, Aug 31, 2013 at 08:05:26PM +0200, Nathan Hüsken wrote:
> Hey,
>
> Is it somehow possible to return "early" in a do block of the IO monad?
> The eqivalent do in C:
>
> void doBlock() {
> if (some preCondition) {
> return;
> }
> ...
> }
>
> ???
Nope. But you can say
do ...
when (not (some condition)) $ do
the
rest
of
the
stuff
You can even indent "the rest of the stuff" directly under the 'when'
if you like, though IMO that may be a bit confusing.
-Brent
More information about the Beginners
mailing list