Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Proper use of exit{Success,Failure} (Vale Cofer-Shabica)
   2. Re:  Proper use of exit{Success,Failure}
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   3. Re:  Proper use of exit{Success,Failure} (Alex Hammel)
   4. Re:  Proper use of exit{Success,Failure} (Vale Cofer-Shabica)


----------------------------------------------------------------------

Message: 1
Date: Tue, 9 Jun 2015 11:25:43 -0400
From: Vale Cofer-Shabica <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Proper use of exit{Success,Failure}
Message-ID:
        <caazfv4tk6zvyj3bnh4hdualm6z++qyummg_h7rlddip_p53...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Dear all,

I'm writing a command line program which may need to exit early based
on some condition. Because of the pipeline the program is a part of, I
want to be able to control the exit status when it does terminate. I
can successfully use 'error' to indicate failure, but also want to
exit early with success (or any other status). Here's what I've
managed:

>import System.Exit (exitSuccess)
>import Control.Monad (when)

>main = do

... code to reasonably initialize condition, e.g.:

>  let condition = True
>  when condition (putStrLn "Bailing out.")>>exitSuccess>>(return ())

... program continues

If I remove ">>(return ())" my code will not typecheck because
"exitSuccess :: IO a". But this looks ugly and smells sufficiently
like a kludge that I presume there is a better way to do it.

Any suggestions appreciated,
vale


------------------------------

Message: 2
Date: Tue, 9 Jun 2015 20:57:52 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Proper use of exit{Success,Failure}
Message-ID:
        <CAJbEW8P3h9YXceFuA54dpvWP+aG7CsRG-4rqEJpN=uqmy6u...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Try `Control.Monad.void`. It is equivalent of adding `>> return ()` to the
end of a block.

void $ do
 ...

On 9 June 2015 at 20:55, Vale Cofer-Shabica <[email protected]>
wrote:

> Dear all,
>
> I'm writing a command line program which may need to exit early based
> on some condition. Because of the pipeline the program is a part of, I
> want to be able to control the exit status when it does terminate. I
> can successfully use 'error' to indicate failure, but also want to
> exit early with success (or any other status). Here's what I've
> managed:
>
> >import System.Exit (exitSuccess)
> >import Control.Monad (when)
>
> >main = do
>
> ... code to reasonably initialize condition, e.g.:
>
> >  let condition = True
> >  when condition (putStrLn "Bailing out.")>>exitSuccess>>(return ())
>
> ... program continues
>
> If I remove ">>(return ())" my code will not typecheck because
> "exitSuccess :: IO a". But this looks ugly and smells sufficiently
> like a kludge that I presume there is a better way to do it.
>
> Any suggestions appreciated,
> vale
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150609/e946d9a2/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 09 Jun 2015 15:38:15 +0000
From: Alex Hammel <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing
        List - Discussion of primarily beginner-level topics related to
        Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Proper use of exit{Success,Failure}
Message-ID:
        <CA+_xFeoZ76QrZncXe-bd88KEmSRtsoZ7+STOLNVsvh=d2y2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

exitSuccess :: IO a means that exitSuccess type-checks for any `a`. Your
program should typecheck without `void`. I suspect you've got a stray paren.

This prints "Bailing out." and exits zero for me:

module Main where

import System.Exit (exitSuccess)
import Control.Monad (when)

main = do
    let condition = True
    when condition (putStrLn "Bailing out." >> exitSuccess)
    putStrLn "Continuing normally..."


On Tue, 9 Jun 2015 at 08:27 Sumit Sahrawat, Maths & Computing, IIT (BHU) <
[email protected]> wrote:

> Try `Control.Monad.void`. It is equivalent of adding `>> return ()` to the
> end of a block.
>
> void $ do
>  ...
>
> On 9 June 2015 at 20:55, Vale Cofer-Shabica <[email protected]>
> wrote:
>
>> Dear all,
>>
>> I'm writing a command line program which may need to exit early based
>> on some condition. Because of the pipeline the program is a part of, I
>> want to be able to control the exit status when it does terminate. I
>> can successfully use 'error' to indicate failure, but also want to
>> exit early with success (or any other status). Here's what I've
>> managed:
>>
>> >import System.Exit (exitSuccess)
>> >import Control.Monad (when)
>>
>> >main = do
>>
>> ... code to reasonably initialize condition, e.g.:
>>
>> >  let condition = True
>> >  when condition (putStrLn "Bailing out.")>>exitSuccess>>(return ())
>>
>> ... program continues
>>
>> If I remove ">>(return ())" my code will not typecheck because
>> "exitSuccess :: IO a". But this looks ugly and smells sufficiently
>> like a kludge that I presume there is a better way to do it.
>>
>> Any suggestions appreciated,
>> vale
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> --
> Regards
>
> Sumit Sahrawat
>  _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150609/271d0780/attachment-0001.html>

------------------------------

Message: 4
Date: Tue, 9 Jun 2015 12:19:40 -0400
From: Vale Cofer-Shabica <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Proper use of exit{Success,Failure}
Message-ID:
        <CAAzfV4SVEtaq+ce3udhxg1wTxSWXx45=68opz0q56oadx+8...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Thank you Alex, Sumit!

I did indeed have stray parentheses. I feel a bit silly for convincing
myself that something with my types was wrong when it was just an
error in grouping. Thanks for the clarification and the note about
void.

-vale



On Tue, Jun 9, 2015 at 11:38 AM, Alex Hammel <[email protected]> wrote:
> exitSuccess :: IO a means that exitSuccess type-checks for any `a`. Your
> program should typecheck without `void`. I suspect you've got a stray paren.
>
> This prints "Bailing out." and exits zero for me:
>
> module Main where
>
> import System.Exit (exitSuccess)
> import Control.Monad (when)
>
> main = do
>     let condition = True
>     when condition (putStrLn "Bailing out." >> exitSuccess)
>     putStrLn "Continuing normally..."
>
>
> On Tue, 9 Jun 2015 at 08:27 Sumit Sahrawat, Maths & Computing, IIT (BHU)
> <[email protected]> wrote:
>>
>> Try `Control.Monad.void`. It is equivalent of adding `>> return ()` to the
>> end of a block.
>>
>> void $ do
>>  ...
>>
>> On 9 June 2015 at 20:55, Vale Cofer-Shabica <[email protected]>
>> wrote:
>>>
>>> Dear all,
>>>
>>> I'm writing a command line program which may need to exit early based
>>> on some condition. Because of the pipeline the program is a part of, I
>>> want to be able to control the exit status when it does terminate. I
>>> can successfully use 'error' to indicate failure, but also want to
>>> exit early with success (or any other status). Here's what I've
>>> managed:
>>>
>>> >import System.Exit (exitSuccess)
>>> >import Control.Monad (when)
>>>
>>> >main = do
>>>
>>> ... code to reasonably initialize condition, e.g.:
>>>
>>> >  let condition = True
>>> >  when condition (putStrLn "Bailing out.")>>exitSuccess>>(return ())
>>>
>>> ... program continues
>>>
>>> If I remove ">>(return ())" my code will not typecheck because
>>> "exitSuccess :: IO a". But this looks ugly and smells sufficiently
>>> like a kludge that I presume there is a better way to do it.
>>>
>>> Any suggestions appreciated,
>>> vale
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>>
>>
>> --
>> Regards
>>
>> Sumit Sahrawat
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 84, Issue 16
*****************************************

Reply via email to