
I'm sure variations of this exist, but for some reason I didn't find any while searching, so I made my own. The idea is for using haskell on the command line instead of perl or awk etc. https://github.com/jimcrayne/hk

This announcement left me totally amazed at the realization that neither "runhaskell" nor "ghci" seem to have a command-line option equivalent to "-c" in Bourne shell. Am I missing something terribly obvious? Best regards, Peter

On Thu, Feb 5, 2015 at 6:42 PM, Peter Simons
This announcement left me totally amazed at the realization that neither "runhaskell" nor "ghci" seem to have a command-line option equivalent to "-c" in Bourne shell.
ghc -e. (Similarly ghci and runghc are really custom invocations of ghc.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Fri, Feb 06, 2015 at 12:42:14AM +0100, Peter Simons wrote:
This announcement left me totally amazed at the realization that neither "runhaskell" nor "ghci" seem to have a command-line option equivalent to "-c" in Bourne shell.
Am I missing something terribly obvious?
How about ghc -e 'do { putStrLn "What is your name?"; name <- getLine; putStrLn $ "Hello " ++ name }'

Note the hk script gives you a richer default environment, including System.Environment and a bunch of other commonly used modules. Also, some magic to sort of detect what you want, in the case of whether you give it a pure function vs an IO etc. For one offs on the command line, a slightly less picky type check seems to make sense in my opinion. In the case that it doesn't work, it lets you edit the script in a text editor, there by showing you what the real haskell looks like. Not that I am especially proud, the implementation could be cleaned up a lot I am sure, but the user interface is failry nice I think. One caveat I probably should mention in the README but didn't, is that your script is copied to a file stored under /tmp, so you don't want to put passwords or anything of that matter in it. On Thu, Feb 5, 2015 at 6:46 PM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Fri, Feb 06, 2015 at 12:42:14AM +0100, Peter Simons wrote:
This announcement left me totally amazed at the realization that neither "runhaskell" nor "ghci" seem to have a command-line option equivalent to "-c" in Bourne shell.
Am I missing something terribly obvious?
How about
ghc -e 'do { putStrLn "What is your name?"; name <- getLine; putStrLn $ "Hello " ++ name }' _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Sorry to reply to myself, but actually passwords on the command line are
never secure. The secure thing is to use a file descripter to input that
information such as STDIN. Thus this is not really a failing of hk.
On Thu, Feb 5, 2015 at 7:35 PM, James Crayne
Note the hk script gives you a richer default environment, including System.Environment and a bunch of other commonly used modules.
Also, some magic to sort of detect what you want, in the case of whether you give it a pure function vs an IO etc. For one offs on the command line, a slightly less picky type check seems to make sense in my opinion. In the case that it doesn't work, it lets you edit the script in a text editor, there by showing you what the real haskell looks like.
Not that I am especially proud, the implementation could be cleaned up a lot I am sure, but the user interface is failry nice I think.
One caveat I probably should mention in the README but didn't, is that your script is copied to a file stored under /tmp, so you don't want to put passwords or anything of that matter in it.
On Thu, Feb 5, 2015 at 6:46 PM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Fri, Feb 06, 2015 at 12:42:14AM +0100, Peter Simons wrote:
This announcement left me totally amazed at the realization that neither "runhaskell" nor "ghci" seem to have a command-line option equivalent to "-c" in Bourne shell.
Am I missing something terribly obvious?
How about
ghc -e 'do { putStrLn "What is your name?"; name <- getLine; putStrLn $ "Hello " ++ name }' _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Feb 5, 2015 at 6:35 PM, James Crayne
Note the hk script gives you a richer default environment, including System.Environment and a bunch of other commonly used modules.
Been there, done that :-). My eddie program "cabal install eddie" is specifically designed for using haskell in shell scripts, so has a slew of options for pre & post-processing the input and handling files as arguments. It got some traction for windows users, but not on systems that have the unix tools set. The unix tools already cover most common use cases, with languages designed for it. On those systems, it's more popular for testing expressions before putting them in a program. Looks like hk will be better for that. Not that I am especially proud, the implementation could be cleaned up a
lot I am sure, but the user interface is failry nice I think.
Ditto for eddie. My first real program, now four years old. it's desperately in need of a rewrite, but I've failed to find time for it for a year or so now.
participants (5)
-
Brandon Allbery
-
James Crayne
-
Mike Meyer
-
Peter Simons
-
Tom Ellis