IO platform for testing

Hello all, first I have to apologise for my English. So, I don't fully understand haskells IO, but I need some testing 'main' function: ./bundle01 <cmd> <arg1> <arg2> ... I more apoarches, but no one worked. Now I tried this: m01_mod :: Int -> Int -> Int b01_mod a b = a mod b main = do (cmd:ss) <- getArgs putStrLn ( if (cmd == "mod") then do show (b01_mod (read (ss!!1)) (read (ss!!2))) else do "unknown command!") Please, send me somethung like this (I need to understand it). I need runing more <cmd>s and with various argument counts and types. All functions "in a bundle" should be in one file. Thanks to you all :) Matej 'Yin' Gagyi

On 2005 July 16 Saturday 11:19, yin wrote:
I need some testing 'main' function:
./bundle01 <cmd> <arg1> <arg2> ...
Your code is close to working. Most likely the detail which gave you trouble is the syntax for mod. It should be
b01_mod a b = a `mod` b Infix operator names in Haskell all use backquotes.
There are some other, minor problems -- for indexing you need ss!!0, the name m01_mod, and you may need an 'import' to make getArgs visible.

yin
first I have to apologise for my English.
Don't worry about that.
./bundle01 <cmd> <arg1> <arg2> ...
I more apoarches, but no one worked. Now I tried this:
m01_mod :: Int -> Int -> Int
What's m01? You define b01 below:
b01_mod a b = a mod b
You must type that "mod a b" or "a `mod` b".
main = do (cmd:ss) <- getArgs putStrLn ( if (cmd == "mod") then do
You don't need the "do" here. Since the type of the entire "if" statement is a String (not an IO String) this is an error.
show (b01_mod (read (ss!!1)) (read (ss!!2))) else do "unknown command!")
Please, send me somethung like this (I need to understand it). I need runing more <cmd>s and with various argument counts and types. All functions "in a bundle" should be in one file.
Otherwise, looks roughly correct to me... The program will crash with a meaningless error if they don't enter any args. peace, isaac

Isaac Jones wrote:
yin
writes: ./bundle01 <cmd> <arg1> <arg2> ...
I more apoarches, but no one worked. Now I tried this:
m01_mod :: Int -> Int -> Int
What's m01? You define b01 below:
oops! "m01" propably is a halucination of my keyboard :)
main = do (cmd:ss) <- getArgs putStrLn ( if (cmd == "mod") then do
You don't need the "do" here. Since the type of the entire "if" statement is a String (not an IO String) this is an error.
it looks more like bash... I'm familiar with it...
show (b01_mod (read (ss!!1)) (read (ss!!2))) else do "unknown command!")
Please, send me somethung like this (I need to understand it). I need runing more <cmd>s and with various argument counts and types. All functions "in a bundle" should be in one file.
I need a module Main. So, when I write some function and save it in file funcsXX.hs and compile all the files, the result should be a program, which will execute my functions. I need it to test these functions, because I just started to learn Haskell.
Otherwise, looks roughly correct to me... The program will crash with a meaningless error if they don't enter any args.
Should I handle incorect situations? How does exception in Haskell work... Oh, yeah... solved partialy this problem: delta_encode :: [Int] -> [Int] delta_encode x:y:zs = x : (deltra_encode ((x + y) : zs)) delta_encode _ = _ -- Is this correct, I wroted it from my head delta_decode ... ... main = do (cmd:ss) <- getArgs putStrLn ( if (cmd == "encode") then show (delta_encode (map (read) ss) else if (cmd == "decode") "unknown command!") Thanks! Matej 'Yin' Gagyi

Matej 'Yin' Gagyi
Please, send me somethung like this (I need to understand it). I need runing more <cmd>s and with various argument counts and types. All functions "in a bundle" should be in one file.
I need a module Main. So, when I write some function and save it in file funcsXX.hs and compile all the files, the result should be a program, which will execute my functions. I need it to test these functions, because I just started to learn Haskell.
That is correct. I'm not sure what your question is. After writing this file (the beginning should read module Main where...) use GHC to compile it; lets call it yinTest: ghc --make YourFile.hs -o yinTest now hopefully "./yintest mod 4 2" will do the right thing!
Otherwise, looks roughly correct to me... The program will crash with a meaningless error if they don't enter any args.
Should I handle incorect situations? How does exception in Haskell work...
When I'm writing a small program like this, I usually write something like: main = do args <- getArgs case args of [] -> helpMsg -- empty list ["mod",arg1,arg2] -> ... ... _ -> helpMsg -- any other inputs helpMsg = error "unknown command. Known commands are: 'mod'" peace, isaac
participants (4)
-
Isaac Jones
-
Matej 'Yin' Gagyi
-
Scott Turner
-
yin