Name: Anonymous 2011-10-03 19:27
The language itself is the same over-engineered bullshit as the programs that are written in it.
char *S;
again:
S = readline("Insert your new password:");
if (!isValid(S)) goto again;
printf("Storing in database...");
newtype (Monad m) => MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) }
instance Monad m => Monad (MaybeT m) where
return = MaybeT . return . Just
instance Monad m => MonadPlus (MaybeT m) where
mzero = MaybeT $ return Nothing
mplus x y = MaybeT $ do maybe_value <- runMaybeT x
case maybe_value of
Nothing -> runMaybeT y
Just value -> runMaybeT x
instance MonadTrans MaybeT where
lift = MaybeT . (liftM Just)
getValidPassword :: MaybeT IO String
getValidPassword = do s <- lift getLine
guard (isValid s)
return s
askPassword :: MaybeT IO ()
askPassword = do lift $ putStrLn "Insert your new password:"
value <- getValidPassword
lift $ putStrLn "Storing in database..."