[Haskell-cafe] Trivial question... solve_qe

robert dockins robdockins at fastmail.fm
Wed Jun 15 10:45:42 EDT 2005

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

I don't know of any tutorials like you have described.  Perhaps someone 
else does?

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

You left out some 'Just' constructors.

import System

solve_qe :: Maybe (Double, Double, Double) -> Maybe (Double, Double)
solve_qe Nothing = Nothing
--solve_qe (a, b, c)
solve_qe (Just (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 (a:b:c:[]) = Just (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