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. Re: Data type (Alex Hammel)
2. Unix-style command line arguments and file input?
(Vale Cofer-Shabica)
3. Re: Unix-style command line arguments and file input?
(Michael Orlitzky)
4. Re: Unix-style command line arguments and file input?
(Mike Meyer)
5. Re: Unix-style command line arguments and file input?
(Rianna Morgan)
6. Re: Unix-style command line arguments and file input?
(David McBride)
----------------------------------------------------------------------
Message: 1
Date: Tue, 05 May 2015 16:11:00 +0000
From: Alex Hammel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data type
Message-ID:
<CA+_xFepqz2mLRtDxnEC1PHmgGx4qAE8onNrcp97X_z4fM=m...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Sticking with the Person example, we might want to use a dynamically-bound
function to specify a different greeting message for different values of
Person:
data Person = Person { name :: String , greet :: Person -> String }
anne = Person "Anne" (\p -> "Howdy, " ++ name p ++ ".")
bob = Person "Bob" (\p -> "Hi, " ++ name p ++ "! I'm Bob")
carol = Person "Carol" (\_ -> "'Sup?")
main = do
putStrLn $ anne `greet` bob
putStrLn $ bob `greet` carol
putStrLn $ carol `greet` anne
You could even get really crazy and construct the greeting function at
runtime:
main = do
putStr "Enter a name: "
n <- getLine
putStrL"Enter a greeting: "
greeting <- getLine
let user = Person n (\p -> concat [greeting, ", ", name p, "!"])
bob = Person "Bob" (\p -> concat ["Hello, ", name p, "!"])
putStrLn $ bob `greet` user
putStrLn $ user `greet` bob
$ runhaskell test.hs
Enter a name: Morbo
Enter a greeting: I WILL DESTROY YOU
Hello, Morbo!
I WILL DESTROY YOU, Bob!
On Tue, 5 May 2015 at 08:38 Shishir Srivastava <[email protected]>
wrote:
> Hi Brandon,
>
> Thanks for your response. My example was just a bad turnout which I
> conjured up using tutorials and playing with it.
>
> I was going to follow up my question with the possible practical use of
> why and where someone would use such a construct to wrap a function inside
> a new data-type.
>
> For all that matters I could have used 'length' function directly to get
> the same output.
>
> I appreciate that you already have given the practical example but
> anything more basic for beginners to highlight the usage would be helpful.
>
> Thanks,
> Shishir
>
>
> On Tue, May 5, 2015 at 4:28 PM, Shishir Srivastava <
> [email protected]> wrote:
>
>> Thanks Matthew - that was crisp !
>>
>> Cheers,
>> Shishir
>>
>
> _______________________________________________
> 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/20150505/17e1069d/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 5 May 2015 13:43:48 -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] Unix-style command line arguments and
file input?
Message-ID:
<CAAzfV4T2-4_LMgMOGH+He+wCQuhK_n5nsUdELpNi=wbej1c...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hello all,
Punchline first: What's the "best practice" way of doing unix-style
command line argument and file input processing in Haskell?
Background:
I'm using Haskell to write programs that act like well-behaved,
pipe-friendly unix tools. i.e., the following are all equivalent:
% ./prog file
% ./prog < file
% cat file | ./prog
Thus far, I've done this by directly inspecting the first element of
System.Environment.getArgs, which has been fine thus far.
I'd also like to be able to take simple command line arguments
(boolean flags and numeric parameters) and the above doesn't adapt
well to that case. I'd like to do this in the idiomatic, "standard"
way (a la getopt() in C). Browsing through the wiki page on command
line argument parsers [1] gave me a bewildering array of options. I'm
not really sure where to start, though I remember reading a blanket
endorsement of optparse-applicative somewhere.
Any pointers or examples that address my use-case would be much appreciated.
-vale
[1]: https://wiki.haskell.org/Command_line_option_parsers
------------------------------
Message: 3
Date: Tue, 05 May 2015 13:58:58 -0400
From: Michael Orlitzky <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Unix-style command line arguments and
file input?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
On 05/05/2015 01:43 PM, Vale Cofer-Shabica wrote:
> Hello all,
>
> Punchline first: What's the "best practice" way of doing unix-style
> command line argument and file input processing in Haskell?
>
> Background:
> I'm using Haskell to write programs that act like well-behaved,
> pipe-friendly unix tools. i.e., the following are all equivalent:
>
> % ./prog file
> % ./prog < file
> % cat file | ./prog
>
> Thus far, I've done this by directly inspecting the first element of
> System.Environment.getArgs, which has been fine thus far.
>
I use CmdArgs for this. I think the simplest example is,
https://hackage.haskell.org/package/email-validator
And one with multiple modes:
https://hackage.haskell.org/package/hath
It's not *quite* what you asked for: I use e.g. `hath -i file` to mean
the same thing as `hath < file`, but that's as close as I got.
------------------------------
Message: 4
Date: Tue, 5 May 2015 13:07:43 -0500
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Unix-style command line arguments and
file input?
Message-ID:
<CAD=7U2B6EcTctQsG0st5hFH-S2gczV7ZRoLO1xf=4xfh+c9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, May 5, 2015 at 12:58 PM, Michael Orlitzky <[email protected]>
wrote:
> I use CmdArgs for this. I think the simplest example is,
>
> https://hackage.haskell.org/package/email-validator
>
> And one with multiple modes:
>
> https://hackage.haskell.org/package/hath
>
> It's not *quite* what you asked for: I use e.g. `hath -i file` to mean
> the same thing as `hath < file`, but that's as close as I got.
>
I also use CmdArgs, though I'm not positive it's still the best choice.
eddie (http://chiselapp.com/user/mwm/repository/eddie/doc/tip/README.md)
correctly handles the cases you want, and in additions makes:
$ cat cat file1 file2 file3 | ./prog
$ ./prog file1 file2 file3
do the same thing. However, it's a bit complicated, as eddie has multiple
interacting options, an accumulating option, and defaults the first
argument to an option and the rest to files to be processed. Figure out the
simpler examples first.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150505/7693ce08/attachment-0001.html>
------------------------------
Message: 5
Date: Tue, 05 May 2015 11:10:38 -0700
From: Rianna Morgan <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Unix-style command line arguments and
file input?
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi there,
I've had fun using cmdargs[1]. Here are several sites that I found to be
very helpful in learning how to use the package:
- This was probably the single most helpful bit of example code[2] that
I found because it illustrates how to have multiple modes that take
different option flags better than other tutorials.
- Neil Mitchell, the author of cmdargs, has some nice example[3] code[4]
that is also useful for seeing how the library works.
- Here is another an example[5] that shows how to make Hello World take
a few basic command arguments.
Hope this helps,
--
Rianna Morgan [email protected]
On Tue, May 5, 2015, at 10:43 AM, Vale Cofer-Shabica wrote:
> Hello all,
>
> Punchline first: What's the "best practice" way of doing unix-style
> command line argument and file input processing in Haskell?
>
> Background: I'm using Haskell to write programs that act like
> well-behaved, pipe-friendly unix tools. i.e., the following are all
> equivalent:
>
> % ./prog file ./prog < file cat file | ./prog
>
> Thus far, I've done this by directly inspecting the first element of
> System.Environment.getArgs, which has been fine thus far.
>
> I'd also like to be able to take simple command line arguments
> (boolean flags and numeric parameters) and the above doesn't adapt
> well to that case. I'd like to do this in the idiomatic, "standard"
> way (a la getopt() in C). Browsing through the wiki page on command
> line argument parsers [1] gave me a bewildering array of options. I'm
> not really sure where to start, though I remember reading a blanket
> endorsement of optparse-applicative somewhere.
>
> Any pointers or examples that address my use-case would be much
> appreciated.
>
> -vale
>
> [1]: https://wiki.haskell.org/Command_line_option_parsers
> _______________________________________________
> Beginners mailing list [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Links:
1. https://hackage.haskell.org/package/cmdargs
2.
https://zuttobenkyou.wordpress.com/2011/04/19/haskell-using-cmdargs-single-and-multi-mode/
3. http://neilmitchell.blogspot.com/2010/08/cmdargs-example.html
4. http://community.haskell.org/~ndm/cmdargs/
5. http://spin.atomicobject.com/2012/12/13/using-haskells-cmdargs-package/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150505/35d3a5f5/attachment-0001.html>
------------------------------
Message: 6
Date: Tue, 5 May 2015 14:12:58 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Unix-style command line arguments and
file input?
Message-ID:
<CAN+Tr427NbN3XeUBozXdbmbyz7myqm-oRu71F=rgdmjtwj9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
While I used to use cmdargs, at some point I switched to
optparse-applicative and never strayed. My only complain about it is that
it uses strings everywhere instead of text.
On Tue, May 5, 2015 at 1:43 PM, Vale Cofer-Shabica <
[email protected]> wrote:
> Hello all,
>
> Punchline first: What's the "best practice" way of doing unix-style
> command line argument and file input processing in Haskell?
>
> Background:
> I'm using Haskell to write programs that act like well-behaved,
> pipe-friendly unix tools. i.e., the following are all equivalent:
>
> % ./prog file
> % ./prog < file
> % cat file | ./prog
>
> Thus far, I've done this by directly inspecting the first element of
> System.Environment.getArgs, which has been fine thus far.
>
> I'd also like to be able to take simple command line arguments
> (boolean flags and numeric parameters) and the above doesn't adapt
> well to that case. I'd like to do this in the idiomatic, "standard"
> way (a la getopt() in C). Browsing through the wiki page on command
> line argument parsers [1] gave me a bewildering array of options. I'm
> not really sure where to start, though I remember reading a blanket
> endorsement of optparse-applicative somewhere.
>
> Any pointers or examples that address my use-case would be much
> appreciated.
>
> -vale
>
> [1]: https://wiki.haskell.org/Command_line_option_parsers
> _______________________________________________
> 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/20150505/ec91700f/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 83, Issue 5
****************************************