[Haskell-cafe] Trivial question... solve_qe

Matej 'Yin' Gagyi yin at atom.sk
Sun Jun 12 11:29:48 EDT 2005

Hi all!

I'm new to Haskell... absolutely new. I need some practice, but little
problem seems to me like unresolvable... Is there some tutorial of
"Exercise, set of resolutions" pairs type?

My english is very bat, so there is it in a picture:

Exercise 1: hello world
Hint: use 'putStrLn'
Resolution 1.1
Resolution 1.2

Exercise 2: write functions 'max_num', 'solve_quad_equation', 'reverse_ary'
Hint: (Explanation of some technics)

Excercise 3: Use do-notation to reverse word in a line read from stdin
Hint: Use Exercise 2... (Explain how 'do' works and what to do in common
error sitations)

So, in a word: I need a tutorial for dummies

Now, my current problem is: my program for solving quadratic equation
won't compile...

import System

solve_qe :: Maybe (Double, Double, Double) -> Maybe (Double, Double)
solve_qe Nothing = Nothing
solve_qe (a, b, c)
    | d >= 0 = Just ((-b + (sqrt d)) / (2 * a), (-b - (sqrt d)) / (2 * a))
    | otherwise = Nothing
    where d = b^2 - 4*a*c

evalArgs :: [String] -> Maybe (Double, Double, Double)
evalArgs (a:b:c:[]) = (read a, read b, read c)
evalArgs _ = Nothing

main = do
    args <- getArgs
    print (solve_qe (evalArgs args))

More information about the Haskell-Cafe mailing list