Something simple
Allan
a.d.clark at ed.ac.uk
Thu Jul 17 15:57:18 EDT 2008
Hi
Generally I would write a function to deal with arguments such that they
needn't necessarily come from the command-line.
So I write a function of type :: [ String ] -> IO ()
My general pattern is therefore
main :: IO ()
main = getArgs >>= processArgs
processArgs :: [ String ] -> IO ()
processArgs [ times, dice ] = {- logic for what you want here -}
processArgs _ = error "You must provide exactly two
arguments"
attached is a sample script which I always start from when writing a
simple program (it's actually in 'yi' as a template).
regards
allan
Chad Wilson wrote:
> I am a gamer. Table top RPGs, war games, board games, etc. Since my
> laptop is pen-based, I has been handier to keep it at the table than
> paper. As a result, I have been experimenting with making dice
> rollers to have yet another item not needed on the table. Sure, it
> takes away some of the tradition, but it makes for carrying fewer
> things. I have written various dice roll simulators in xblite, ruby
> and some other dynamics, but this seems like an interesting exercise
> to try in Haskell.
>
> My first goal is to figure out how to get the command-line arguments.
> As I did with the other languages, my first program in this
> development simply retrieved the arguments and printed them. So, here
> it is.
>
> import System.Environment
>
> main = do
> args <- getArgs
> print args
>
> Very simple and to the point. Now I need to dig into the manual and
> figure out the next simple progression...taking 2 arguments and doing
> something to them akin to:
>
> roll 1 6
>
> This would roll 1, 6-sided die, or 1d6 in gamer terms and print the
> result.
>
> I figure the best way to learn a new language is to apply it something
> I might actually use it for.
>
> --
> Chad Wilson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SampleScript.hs
Type: text/x-haskell
Size: 1646 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/beginners/attachments/20080717/414ac4fc/SampleScript.bin
More information about the Beginners
mailing list